1

假设这个查询,

SELECT  
    SUM (Quantity) OVER (Partition By Symbol ORDER BY PositionID ASC ROWS UNBOUNDED PRECEDING) as RemainedQty

是否可以在窗口函数中定义条件?在此示例中,我需要在每一行中获取不同情况下的 SUM(数量)。一些东西(假设)像:

SELECT
SUM (Quantity) OVER (Partition By ...) Where SomeColumn='X' as RemainedQty_X,
SUM (Quantity) OVER (Partition By ...) Where SomeColumn='Y' as RemainedQty_Y ...
4

1 回答 1

1

对的,这是可能的。

从表中选择 SUM(当 SomeColumn='X' 然后 Quantity else 0 结束时的情况)作为 sumx,SUM(当 SomeColumn='y' 然后 Quantity else 0 结束时的情况)作为 sumy

于 2014-09-06T07:40:30.170 回答