Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help !! Calculate Rolling average for last 4 weeks Expand / Collapse
Author
Message
Posted Wednesday, December 19, 2012 9:24 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 12:13 PM
Points: 69, Visits: 289
Hi All,

I need your help.

Database: SQL SERVER 2008R2

I want to calculte for a year and a week the average of value of the 4 last weeks.

I have data a table like that:

YEAR WEEKS VALUE
2012 1 3000
2012 2 5000
2012 3 6000
2012 4 7000
2012 5 8000
2012 6 9000
2012 7 1000
2012 8 6000

And I want that :

YEAR WEEKS VALUE
2012 1 ( Average value for week 49, 50, 51, 52 for the year 2011)
2012 2 ( Average value for week 50, 51, 52 for the year 2011 and week 1 for the year 2012)
2012 3 ( Average value for week 51, 52 for the year 2011 and week 1, 2 for the year 2012)
2012 4 ( Average value for week 52 for the year 2011 and week 1, 2, 3 for the year 2012)
2012 5 5250 -> ( Average value for week 1, 2, 3 , 4 for the year 2012)
2012 6 6500 -> ( Average value for week 2, 3 , 4, 5 for the year 2012)


Thank U for your help
Post #1398761
Posted Wednesday, December 19, 2012 10:35 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:39 PM
Points: 20,792, Visits: 32,705
Duplicate post, please post all replies here.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1398774
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse