Fakhryan Albar
Fakhryan Albar

Reputation: 113

Sum all previous every row

Result table

enter image description here

my expectation query

enter image description here

help me please, how to get data sum_of_previous from total_point like that

I am using lag() but that only get last 1 previous field i need all previous every row running and sum that

Upvotes: 0

Views: 88

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93694

Use SUM() Over() window aggregate function instead of LAG. LAG can used to find the only one previous row in ordered set

Select id,
       total_point,
       sum(total_point)over(order by Id)
From yourtable 

Upvotes: 2

Related Questions