本文介绍了Oracle Sql中的列行转置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的查询,给出了这个结果

Hi I have a simple query which give this result

我想按如下修改它. 名称"列成为列标题,而"studentID"列成为第一行

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

推荐答案

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));

这篇关于Oracle Sql中的列行转置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:04