November 25, 2014 at 12:04 am
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
November 25, 2014 at 1:18 am
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 ..
November 25, 2014 at 8:29 am
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
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply