我正在尝试拥有"累积客户"在前5"累积客户"之后NULL
:
SUM(Customer) OVER (PARTITION BY Product ORDER BY date DESC) cumulative_customers
最终输出将如下所示:
答案 0 :(得分:1)
答案 1 :(得分:0)
如果您不想要子查询,可以使用case
执行此操作:
select (case when SUM(Customer) OVER (PARTITION BY Product ORDER BY date DESC) <= 5
then SUM(Customer) OVER (PARTITION BY Product ORDER BY date DESC)
end) as cumulative_customers
如果您需要子查询或CTE,Erwin的解决方案也可以使用。