There is a table table Picture1

using SELECT commands you need to display as in the picture2 Picture2

Closed due to the fact that off-topic participants Denis , aleksandr barakin , Nicolas Chabanovsky Nov 14 '16 at 7:30 .

  • Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What is the logic of construction? Why are there several columns in a row with type_id ? - Viktorov
  • Simply, there is a table that should be output as in the second image using SELECT. Here, type_id is not a primary key, but simply a column, and can accept non-unique parameters. It turns out is divided by type_id, if type_id is different, then a new column is added - assyl.d
  • It seems that since it is not universally possible to display the picture or I do not know the way to do it. Are you sure you drew the picture correctly? In the title of the question you wrote that print the rows as columns. What you drew is different - Viktorov
  • And if there is another type_id, I understand that you want columns for it too? ... It's impossible. In a SQL query, the number of columns must be specified in advance. Such transformations should be performed on the client. Those. it is not a particular problem to beat concretely into 3 groups horizontally, but the groups will be exactly 3 and the values ​​55, 56, 57 will be tightly sewn into the query - Mike
  • I apologize if I asked the wrong question! Well, in general in the picture I think it is clear!)) There will be only three groups! Just need to form and display in this form! - assyl.d

1 answer 1

 select * from ( select type_id, col_1, col_2, row_number() over(partition by type_id order by col_1) as grp from T ) pivot( max(type_id) as type_id, max(col_1) as col_1, max(col_2) as col_2 for(type_id) in(55, 56, 57) ) 
  • Thank you very much! That's right))) - assyl.d