V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lihui0234
V2EX  ›  数据库

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

  •  
  •   lihui0234 · May 16, 2016 · 1341 views
    This topic created in 3640 days ago, the information mentioned may be changed or developed.

    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

    实现这样的如何写???

    2 replies    2016-05-17 00:04:50 +08:00
    dexterz
        1
    dexterz  
       May 16, 2016
    crosstable 查询用 pivot 啊
    anthow
        2
    anthow  
       May 17, 2016
    有自带的行转列函数~ WMSYS.WM_CONCAT() 你看看
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1214 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:11 · PVG 01:11 · LAX 10:11 · JFK 13:11
    ♥ Do have faith in what you're doing.