Subject | RE: [firebird-support] How to do a running total in SQL |
---|---|
Author | Maya Opperman |
Post date | 2015-10-23T06:56:43Z |
>>In Firebird 3 it will be possible with window functions. In Firebird 2.5 I don't know a way in pure SQL.
>>Mark
Great, thanks Mark.
Cool, so I’ll be doing something like this, when Firebird 3 is available:
select emp_no, salary,
sum(salary) over (order by salary) cum_salary,
sum(salary) over (order by salary desc) cum_salary_desc
from employee order by emp_no;
EMP_NO SALARY CUM_SALARY CUM_SALARY_DESC
======= ===================== =====================
2 105900.00 1990493.02 113637875.00
4 97500.00 1680929.02 113939039.00
28 22935.00 22935.00 115522468.02
121 99000000.00 115522468.02 99000000.00
145 32000.00 113210.00 115441258.02
From: http://www.firebirdsql.org/file/community/ppts/fbcon11/fb3windowing.pdf