2017-09-07 37 views
0

有什麼方法可以使用大於pivot表達式的方法嗎?例如:在主表達式中的條件

SELECT 
    MONTH 
    , col1 
    , col2 
FROM 
(
    SELECT month, c1, c2, date1 FROM table1 
) 
PIVOT 
(
    SUM(c1) 
    FOR(c2, date1) IN 
    (
     ('x', < SYSDATE) AS col1 
     , ('x', >= SYSDATE) AS col2 
    ) 
); 

我需要列依賴於sysdate。

+0

請提供樣本數據和預期結果。 –

回答

3

只需使用條件聚合。這是有點不清楚你想要做什麼,但這應該是關閉的:

select month, 
     sum(case when date1 < sysdate then c1 else 0 end) as col1, 
     sum(case when date1 >= sysdate then c1 else 0 end) as col2 
from table1 t1 
group by month