Adding certain Rows specific

  • Hi All,

    I got a table where i need to add certain rows and minus the valu with a row can any one help in this regard.

    I am attaching a image , kindly have a look into it.

    IDC1C2C3C4C5C6

    1551557775

    266201452

    345222266

    441727582

    532556951

    6022022

    7182344142

    8

    Result in the 8 Row

    Sum(id(2,3,4)-sum(id(6,7))

    Regards

    Kumar

  • kriskumark96 (11/25/2014)


    Hi All,

    I got a table where i need to add certain rows and minus the valu with a row can any one help in this regard.

    I am attaching a image , kindly have a look into it.

    IDC1C2C3C4C5C6

    1551557775

    266201452

    345222266

    441727582

    532556951

    6022022

    7182344142

    8

    Result in the 8 Row

    Sum(id(2,3,4)-sum(id(6,7))

    Regards

    Kumar

    Provide details in reliable form, so that it will increase the chance to be answered..

    Narrate it with more examples ..

  • Why do you want the result in the 8th row? That should be done in the front end.

    To do a sum like that you need CASE.

    SELECT SUM(CASE WHEN id IN(2,3,4) THEN C1 ELSE 0 END)

    - SUM(CASE WHEN id IN(6,7) THEN C1 ELSE 0 END)

    FROM MyTable

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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