Below given table ABC has column Num and second column should be created by adding the values in column first. Table ABC
Num
1
2
3
4
5
Output
Num Num2
1 1
2 3
3 6
4 9
5 12
Oracle supports the ANSI standard method of calculating cumulative sums:
select num, sum(num) over (order by num)
from t;
And you can do this in MYSQL
SELECT T.* ,
@SUM:=@SUM + T.num AS RunningTotal
FROM (SELECT @SUM:=0) S,T
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.