Oracle Sql中的列行转置

时间:2013-10-01 02:52:29

标签: oracle oracle11g

您好,我有一个简单的查询,可以提供此结果

enter image description here

我想修改如下。 Name列成为列标题,studentID列成为第1行

enter image description here

1 个答案:

答案 0 :(得分: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));