SQL Script

  • Hi,

    Below is the data in my table

    MarketQtrWeek % Over %Change

    HD Q1'09 1 3.91% 3.91%

    HD Q1'09 2 5.00% 5.00%

    HD Q1'09 3 4.32% 4.32%

    HD Q2'09 1 3.26% 7.17%

    HD Q2'09 2 3.04% 8.04%

    HD Q2'09 3 2.05% 6.36%

    HD Q3'09 1 1% 8.17%

    HD Q3'09 2 1% 9.04%

    HD Q3'09 3 1% 7.36%

    The table has data for Market, Qtr, Week, % Over. I need to calculate %change. %change for Q1 09 will be equal to %over. But for Q2 09, %change will be sum of %over of Q1 and Q2 09 grouped by week. For Q3 09, %change is sum of %Over of Q1, Q2 and Q3 09. How to modify the below script to get the %change as desired.

    Select Market, Qtr, Week, Over from table;

    Thanks

  • Sounds like an issue that fits into the "running total" category.

    You might want to have a look at this link[/url] .



    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]

  • gsanthosh84-663713 (2/3/2010)


    Hi,

    Below is the data in my table

    MarketQtrWeek % Over %Change

    HD Q1'09 1 3.91% 3.91%

    HD Q1'09 2 5.00% 5.00%

    HD Q1'09 3 4.32% 4.32%

    HD Q2'09 1 3.26% 7.17%

    HD Q2'09 2 3.04% 8.04%

    HD Q2'09 3 2.05% 6.36%

    HD Q3'09 1 1% 8.17%

    HD Q3'09 2 1% 9.04%

    HD Q3'09 3 1% 7.36%

    The table has data for Market, Qtr, Week, % Over. I need to calculate %change. %change for Q1 09 will be equal to %over. But for Q2 09, %change will be sum of %over of Q1 and Q2 09 grouped by week. For Q3 09, %change is sum of %Over of Q1, Q2 and Q3 09. How to modify the below script to get the %change as desired.

    Select Market, Qtr, Week, Over from table;

    Thanks

    Are you actually storing single quotes and percent signs in your tables or is this the output from a query?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • It is for output purpose. I showed it as an example.

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

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