V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lihui0234
V2EX  ›  数据库

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

  •  
  •   lihui0234 · 2016-05-16 18:36:26 +08:00 · 699 次点击
    这是一个创建于 2901 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2016-05-17 00:04:50 +08:00
    dexterz
        1
    dexterz  
       2016-05-16 22:15:16 +08:00
    crosstable 查询用 pivot 啊
    anthow
        2
    anthow  
       2016-05-17 00:04:50 +08:00
    有自带的行转列函数~ WMSYS.WM_CONCAT() 你看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3307 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:36 · PVG 20:36 · LAX 05:36 · JFK 08:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.