-1

嗨,我有一个添加所有以前值的场景......

输入是表格的一列

Col
3
5
4
6
9
7
8

我需要以这种方式输出:

Col      Col2
3         3
5         8
4         12
6         18 
9         27
7         34
8         42

请尽快回复

问候, 尼拉吉

4

1 回答 1

0

As long as you have a field to order by, you can use SUM ... OVER to do the running sum;

SELECT Col, SUM(Col) OVER (ORDER BY id) Col2
FROM Table1
ORDER BY id;

An SQLfiddle to test with.

于 2013-11-11T05:35:16.733 回答