I have a table as simple as two columns Name, Date -- It is a table that has "Leads" in it when user inquiries from our website.
I need to produce a data set of lead count of last 10 rolling weeks?
The expected output is suppose to be
Starting Week -- Count
==============
10 SUM(Last 10 weeks)
9 SUM(Starting from Week 9 for Last 10 weeks)
8 SUM(Starting from Week 8 for Last 10 weeks)
and so on.. it will have 10 rows
its like sliding a week back and sum the last 10 weeks from there
any help?
This is exactly what the windowing clause is supposed to do. However, you first need to aggregate the data:
Assuming that you have data on every day, then you want 70 days worth of counts. You get that by summing the counts for 70 days. That would be:
That works for days. To get this by weeks, you need to do something to convert days to weeks and then change the windowing clause. You don't define a week, but this might be close to what you want: