SQL Rolling Average by Day of Week (or Date minus 7)

Viewed 1129

I have a query that pulls data and groups it to:

Date        Type        Total
3/1/2016    Sales       9
3/1/2016    Support     8
3/1/2016    Service     5
3/1/2016    Other       48
3/2/2016    Sales       42
3/2/2016    Support     86
3/2/2016    Service     67
3/2/2016    Other       25
3/2/2016    VIP         12
3/3/2016    Sales       46
3/3/2016    Support     45
3/3/2016    Service     78
3/3/2016    Other       70
3/3/2016    VIP         26

I want to include a rolling average as well. So for 3/1/2016 Sales the rolling average would be for the 10 prior Tuesdays. Essentially:

select average(Total) where Date in ('2/23/2016','2/16/2016','2/9/2016','2/2/2016','1/26/2016','1/19/2016','1/12/2016','1/5/2016','12/29/2015','12/22/2015') and Type = "Sales" 

Is there a way to efficiently do this in 1 query?

3 Answers
Related