Oracle 求助,行列转换问题。。。

2016-05-16 18:36:26 +08:00
 lihui0234

itpub 帖子地址 http://www.itpub.net/thread-2059378-1-1.html 问题是: with t1 as ( select 1 as id,95 as chinese_score,99 as maths_score,95 as english_score,'2016-05-09' as test_month from dual union all select 2 as id,96 as chinese_score,100 as maths_score,98 as english_score,'2016-05-10' as test_month from dual union all select 3 as id,93 as chinese_score,91 as maths_score,93 as english_score,'2016-05-11' as test_month from dual union all select 4 as id,94 as chinese_score,94 as maths_score,89 as english_score,'2016-05-12' as test_month from dual union all select 5 as id,97 as chinese_score,92 as maths_score,92 as english_score,'2016-05-13' as test_month from dual union all select 6 as id,98 as chinese_score,90 as maths_score,97 as english_score,'2016-05-14' as test_month from dual ) select '语文' as lable, max(decode(test_month,'2016-05-09',chinese_score,null)) as "2016-05-09", max(decode(test_month,'2016-05-10',chinese_score,null)) as "2016-05-10", max(decode(test_month,'2016-05-11',chinese_score,null)) as "2016-05-11" from t1 union all select '数学' as lable, max(decode(test_month,'2016-05-09',maths_score,null)) as "2016-05-09", max(decode(test_month,'2016-05-10',maths_score,null)) as "2016-05-10", max(decode(test_month,'2016-05-11',maths_score,null)) as "2016-05-11" from t1 union all select '英语' as lable, max(decode(test_month,'2016-05-09',english_score,null)) as "2016-05-09", max(decode(test_month,'2016-05-10',english_score,null)) as "2016-05-10", max(decode(test_month,'2016-05-11',english_score,null)) as "2016-05-11" from t1

实现这样的如何写???

782 次点击
所在节点    数据库
2 条回复
dexterz
2016-05-16 22:15:16 +08:00
crosstable 查询用 pivot 啊
anthow
2016-05-17 00:04:50 +08:00
有自带的行转列函数~ WMSYS.WM_CONCAT() 你看看

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/279034

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX