SELECT rowid, a, SUM(c0) OVER(ORDER BY rowid) as c
FROM
(
SELECT rowid, a, a - LAG(a, 1) OVER(ORDER BY rowid) as c0
FROM
(
SELECT 1 as rowid, 5 as a union all
SELECT 2 as rowid, 6 as a union all
SELECT 3 as rowid, 5 as a union all
SELECT 4 as rowid, 7 as a union all
SELECT 5 as rowid, 8 as a union all
SELECT 6 as rowid, 3 as a
)t
)t
2条答案
按热度按时间vlf7wbxs1#
你的公式是累加和。下面是一个完整的示例:
0lvr5msh2#
看来可乐只是可乐减去第一排的可乐。
例如
所以这个查询应该可以: