如何在Netezza sql中随着时间的推移进行聚合?
我使用Netezza和 我有这样的桌子如何在Netezza sql中随着时间的推移进行聚合?,sql,Sql,我使用Netezza和 我有这样的桌子 cert_id date value -------- ------------ ------ 01 2018-01-01 2 01 2018-01-02 1 01 2018-01-03 3 02 2018-02-06 2 02 2018-02-07 1 02
cert_id date value
-------- ------------ ------
01 2018-01-01 2
01 2018-01-02 1
01 2018-01-03 3
02 2018-02-06 2
02 2018-02-07 1
02 2018-02-08 4
02 2018-02-09 6
cert_id date value
-------- ------------ ------
01 2018-01-01 2
01 2018-01-02 3
01 2018-01-03 6
02 2018-02-06 2
02 2018-02-07 3
02 2018-02-08 7
02 2018-02-09 13
我希望这个聚合时间表是这样的
cert_id date value
-------- ------------ ------
01 2018-01-01 2
01 2018-01-02 1
01 2018-01-03 3
02 2018-02-06 2
02 2018-02-07 1
02 2018-02-08 4
02 2018-02-09 6
cert_id date value
-------- ------------ ------
01 2018-01-01 2
01 2018-01-02 3
01 2018-01-03 6
02 2018-02-06 2
02 2018-02-07 3
02 2018-02-08 7
02 2018-02-09 13
一种方法使用相关子查询查找滚动和:
SELECT
cert_id,
date,
"value",
(SELECT SUM(t2."value") FROM yourTable t2
WHERE t1.cert_id = t2.cert_id AND t2.date <= t1.date) rolling_sum
FROM yourTable t1
ORDER BY
cert_id,
date;