Moving Average -For 4 weeks

  • Hi ..

    I have Table which Consists of the following Data in it ..

    Datetime Data

    2009-11-08 18:37:08.080 1.45898

    2009-11-08 18:52:08.083 0.682263

    2009-11-08 19:07:08.090 0.377801

    2009-11-08 19:22:08.097 15.1342

    2009-11-08 19:37:08.103 0.454472

    2009-11-08 19:52:08.107 0.643372

    2009-11-08 20:07:08.113 304.813

    2009-11-08 20:22:08.120 458.35

    2009-11-08 20:37:08.127 0.814493

    2009-11-08 20:52:08.130 274.853

    2009-11-08 21:07:08.137 106.836

    2009-11-08 21:22:08.143 11.8152

    2009-11-08 21:37:08.147 0.531143

    2009-11-08 21:52:08.153 0.51892

    2009-11-08 22:07:08.153 0.423359

    .

    .

    .

    .

    .

    .

    2009-12-15 03:20:20.003 13.2219789351478

    For this table data i need to calculate the 4 week moving average ,and add it as a additional column to this table representing it as "moving average"

    How to write a sql query .

    Can any one help me out ...

  • Several questions:

    1) Does "4 weeks" mean to calculate the average for full weeks or is 4 weeks = last 28 days? Based on your example: Dec. 15th is a Tuesday. What data should be included in those "4 weeks"?

    2) Do you need to calculate backward or forward? Meaning: need the values be stored to the first day or the last day of the 4 week period?

    3) Do you need to fill that addtl. column when new values are added or do you plan to calculate the values separately?

    Finally, please read and follow the first link in my signature on how to post sample data. We'd like to get ready to use data together with some expected results to test against.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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