Im looking to recreate the SUM_FUNC_LIMIT column below where a subtraction occurs but is limited to reaching 0.
A SUM() window function will recreate SUM_FUNC, but I cannot create the SUM_FUNC_LIMIT column.
EXCEL FORMULA is =IF(D1+B2<0,0,D1+B2)
ROW [A] | AMOUNT [B] | SUM_FUNC [C] | SUM_FUNC_LIMIT [D] |
---|---|---|---|
1 | 5 | 5 | 5 |
2 | 9 | 14 | 14 |
3 | -6 | 8 | 8 |
4 | -6 | 2 | 2 |
5 | -6 | -4 | 0 |
6 | 3 | -1 | 3 |
7 | -6 | -7 | 0 |
8 | -6 | -13 | 0 |
9 | 7 | -6 | 7 |
10 | 3 | -3 | 10 |
11 | -6 | -9 | 4 |
Any help appreciated.
Have tried many things... but calling a previous entry within a new entry is not possible in SQL.