我有此数据,我想像下面那样计算3天的滚动总和。
注意:必须考虑缺少date
。因此,不仅是最后3行,而且是3个太阳日。
我尝试了使用窗口函数,但是它不起作用:
SELECT
date,
SUM(clicks) OVER (ORDER BY DATE ASC ROWS BETWEEN DATE - INTERVAL '3 day' AND date)
FROM table
答案 0 :(得分:1)
上限应为current row
和range
:
SELECT
date,
SUM(clicks) OVER (ORDER BY DATE ASC range BETWEEN INTERVAL '3 day' PRECEDING AND CURRENT ROW)
FROM table