Adding Column Values

  • Hi

    I want to Add every 7 column values.

    Here is my Table:

    CP CodeTimeTotal Pageviews

    510146/20/20101863092

    510146/21/20101858354

    510146/22/20101740963

    510146/23/20101573342

    510146/24/20101626228

    510146/25/20101637978

    510146/26/20101853239

    530376/20/20103511

    530376/21/20103530

    530376/22/20103715

    530376/23/20104081

    530376/24/20105548

    530376/25/20105728

    530376/26/20105913

    Here is what I want:

    CP Code Total Pageviews

    51014 12153196

    53037 32026

    Total Pageviews in this table has SUM of all Total Pageviews over the last seven days with CP Codes 51014 and 53037.

    Can you guys provide me the T-SQL query or the best possible way to do this?

    Thanks.

  • Novicejatt (7/20/2010)


    Hi

    I want to Add every 7 column values.

    Here is my Table:

    CP CodeTimeTotal Pageviews

    510146/20/20101863092

    510146/21/20101858354

    510146/22/20101740963

    510146/23/20101573342

    510146/24/20101626228

    510146/25/20101637978

    510146/26/20101853239

    530376/20/20103511

    530376/21/20103530

    530376/22/20103715

    530376/23/20104081

    530376/24/20105548

    530376/25/20105728

    530376/26/20105913

    Here is what I want:

    CP Code Total Pageviews

    51014 12153196

    53037 32026

    Total Pageviews in this table has SUM of all Total Pageviews over the last seven days with CP Codes 51014 and 53037.

    Can you guys provide me the T-SQL query or the best possible way to do this?

    Thanks.

    Here is a template... feel free to fill in the blanks as needed

    select CPCode,

    sum(TotalPageviews)

    from yourTable

    where Time between lower-date and higher-date

    and CPCode in (51014,53037)

    group by CPCode

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Hi

    Thankyou very much.

  • Novicejatt (7/20/2010)


    Thankyou very much.

    Glad to help 😉

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Ill try to be more clear in my future posts. Still Learning .............

    Thank you all for ur help.

  • Novicejatt (7/20/2010)


    Ill try to be more clear in my future posts. Still Learning.

    Don't worry about Joe, some people drinks too much coffee 😀

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Viewing 6 posts - 1 through 5 (of 5 total)

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