I have a SQL result like this:
name | points
------+-------
Joe | 2
Joe | 5
Joe | 4
Joe | 1
Each row represents how many points Joe received per event.
Joe has some basic budget, let's say $100.
What I need to do now is to add a field, which will represent actual budget value, when one point means $10 addition. Something like history of budget growth.
The result should look like this:
name | points | budget
------+--------+-------
Joe | 2 | 120
Joe | 5 | 170
Joe | 4 | 210
Joe | 1 | 220
Usage of a variable seems like the best solution to me, but PostgreSQL is not much friendly with it, so I'm looking for a solution using sumarization of first x rows of the result to get actual points sum since the beginning.
Do you have any idea how to do this without subselecting in each row?