I have a table with two columns, date and score. I want to find something like:
- Sum as of 7 days ago
- Sum as of 6 days ago
- …
- Sum as of today
An individual thing could be found with
select sum(score) from my_table
where date <= DateAdd("d", -1, getdate)
But I would like to not have to run a new query every time.
(I am using django, but pure SQL solutions are fine too.)
Use case statements to sum each value you care about.