Convert rows to columns oracle SQL

后端 未结 2 1977
予麋鹿
予麋鹿 2021-01-24 21:56

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

相关标签:
2条回答
  • 2021-01-24 22:49

    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))
    
    0 讨论(0)
  • 2021-01-24 22:55

    If the 'ID' column is the primarykey you can only have one column as primarykey in the table.

    0 讨论(0)
提交回复
热议问题