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
实现这样的如何写???
1
dexterz 2016-05-16 22:15:16 +08:00
crosstable 查询用 pivot 啊
|
2
anthow 2016-05-17 00:04:50 +08:00
有自带的行转列函数~ WMSYS.WM_CONCAT() 你看看
|