I'm not sure what RDBMS you are using and I am aware this is the ANSI sql forum. However in DB2 you can use OLAP functions, but I don't know if these are ANSI compliant.
Anyway in DB2 the following should satisfy your query.
select date,
count,
sum(count) over (order by date) as rolling_sum
from table
order by date.
I believe the straight sql version can be done like so:
select date,
count,
(select count
from table t1
where t1.date < t0.date)
from table t0
order by date;
NOTE: I didn't test this thouroghly and it is pretty early in the morning so be careful ;^) If your RDBMS has a function that helps, by all means, use it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.