I did not find any suitable previous answers hence posting the question. I need to convert rows to columns. The PIVOT examples all convert the rows to a single column whereas m
You could enumerate rows with row_number()
and make pivot
:
SQLFiddle demo
select *
from (
select d.*, row_number() over(partition by type order by id) rn from data d)
pivot (max(type) type, max(id) id for type in ('test1' t1, 'test2' t2))
If the 'ID' column is the primarykey you can only have one column as primarykey in the table.