How can I summarize in each row all the above rows?

70 Views Asked by At

Is it possible to get sum of all the above rows in each row?

Example:

Rows | Count
 1. | 20
 2. | 30
 3. | 10
 4. | 25

And I want to take the follow result

Rows | TotalCount
  1  | 20    (20)
  2  | 50    (20+30) 
  3  | 60    (20+30+10)
  4  | 85    (20+30+10+25) 
1

There are 1 best solutions below

0
On

You want a cumulative sum. In standard SQL, you use a window function for this:

select rows, sum(count) over (order by rows)
from t;