0

I have a table like this

Id    Description   Tot
---    -----    -----
1    aaaa    10
2    bbbb    20
3    cccc    30
4    eeee    40

I want to get the results like this

Id       Name   Mark
---    -----    -----
1    aaaa    10
2    bbbb    20 + row 1.value
3    cccc    30 + row 2.values sum
4    eeee    40 + row 3.values sum

I have used the SQL LAG function but it does not give me the desired result as it only uses the previous rows value and I need the sum

John
  • 263
  • 1
  • 15

1 Answers1

2

You want a cumulative sum:

select t.*, sum(mark) over (order by id) as running_sum
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786