Assuming I have a table with months and totals, I need to return the last 6 months of data, with each month being a total of itself and the preceding 5 months.
Here's sample source data (you can assume the MONTH to be datetime fields):
MONTH QY
7-2008 87
6-2008 33
5-2008 12
4-2008 76
3-2008 14
....
Returning the latest 6 months is easily done with a where, but I'm having difficulties coming up with a derived table for the sums. I'd need July's output number to be the total of July plus the previous 5 months. June would be the same: June plus it's previous 5 months.
I can do it easy enough with a loop and a temp table, but I'd prefer a cleaner solution if one is possible.
Any pointers?
Here's sample source data (you can assume the MONTH to be datetime fields):
MONTH QY
7-2008 87
6-2008 33
5-2008 12
4-2008 76
3-2008 14
....
Returning the latest 6 months is easily done with a where, but I'm having difficulties coming up with a derived table for the sums. I'd need July's output number to be the total of July plus the previous 5 months. June would be the same: June plus it's previous 5 months.
I can do it easy enough with a loop and a temp table, but I'd prefer a cleaner solution if one is possible.
Any pointers?