旋转输出

时间:2019-04-12 07:13:41

标签: sql oracle oracle11g pivot

我在开发查询时遇到了麻烦,在该查询中,我必须连接输出或两个不同的查询,然后旋转或转置该表。由于表中的数据可能随着“ d”的多次选择而增加,因此可以使查询动态化。对于我来说,成为该平台的初学者是一项艰巨的任务。

    -- Output of query 1
        select created, sum(value) as D 1 from XYZ where d = '123' 
         group by created order by created asc


    Created     D 1
    ---------   ---
    2/28/2019   123
    3/1/2019    123
    3/6/2019    645
    3/7/2019    785
    3/8/2019    234

    -- Output of query 2
    select created, sum(value) as D 2 from XYZ where d = '243' 
    group by created order by created asc

    Created     D 2
    ---------   ---
    2/28/2019   46
    3/1/2019    2355
    3/7/2019    347

    -- Expected result
    Created     2/28/2019   3/1/2019    3/6/2019    3/7/2019    3/8/2019
    D 1         123         1236        645         785         2345
    D 2         46          2355        null        347         null

任何建议或帮助都会受到赞赏。

谢谢。

0 个答案:

没有答案