Help !! Calculate Rolling average for last 4 weeks

  • 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

  • Duplicate post, please post all replies here.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply