I am trying to calculate the val column using id column and the previous val column. On Excel, I simply use the formula "=IF(B2=1,1,C1+B2)". How can i reference previous value of my column being computed?
id val
1 1
2 3
3 6
4 10
5 15
6 21
7 28
8 36
9 45
10 55
My query would look like
SELECT id,
Case
When id =1 then 1
Else id+*previousval*
end as val
from
tab