Convert column to row

Asked

Viewed 476 times

3

This is the select of my table, the query I am using follows in the image below:

SS

It brings the normal result, but wanted it to bring this way:

| Id_unica | Pixel | Inch | Quantity |
      18 1080p 15 2

Is it possible guys?

Current select:

SELECT id, id_unica, parametro, descricao, produto FROM inventario WHERE produto='Monitor' GROUP BY parametro ORDER BY parametro ASC;
  • Column names will always be these?

  • Hello. Welcome to SOPT. Prefer to copy the results of the query instead of placing an image (makes it easier to read). Check here how to ask.

  • The name of the Columns equals the value of the parameter variable except Id_unica, which will always be the same name

  • You seem to want to "pivot" the table. I marked the question as duplicate of another whose answer explains the trick to do this.

1 answer

0

Try using it as follows:

SELECT id + id_unica + parametro + descricao + produto 
FROM inventario 
WHERE produto='Monitor' 
GROUP BY parametro 
ORDER BY parametro ASC;

if the + signal does not work in Mysql, try pipe "||" should work.

  • rcaratchuk, it didn’t work this way.

  • I did a quick search on the Internet. SELECT Concat(id, '|' , id_unica , '|' , parameter , '|' , Description , '|' , product FROM inventory WHERE product='Monitor' GROUP BY parameter ORDER BY parameter ASC;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.