Column Row Transpose in Oracle Sql

有些话、适合烂在心里 提交于 2019-12-31 06:52:51

问题


Hi I have a simple query which give this result

And I want to modify it as follows. the Name column becomes the column headers and the studentID column becomes the 1st row


回答1:


WITH t AS
     (SELECT 1001 studentid, 'john' NAME FROM dual
     UNION ALL
     SELECT 1002, 'kane' FROM dual
     )
SELECT * FROM (
SELECT studentid, NAME FROM t)
pivot (max(studentid) for name in ('john' John, 'kane' Kane));


来源:https://stackoverflow.com/questions/19107174/column-row-transpose-in-oracle-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!