2017-09-07 104 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