How to Sum rows like
Sl No
|
Name
|
CN
|
CA
|
CG
|
CO
|
OS
|
1
|
AAA
|
60
|
76
|
45
|
61
|
242
|
2
|
AAB
|
45
|
56
|
46
|
72
|
219
|
3
|
AAC
|
67
|
45
|
47
|
84
|
243
|
4
|
AAD
|
89
|
87
|
87
|
91
|
354
|
5
|
AAE
|
76
|
90
|
67
|
51
|
284
|
6
|
AAF
|
56
|
56
|
66
|
41
|
219
|
7
|
AAG
|
45
|
45
|
56
|
44
|
190
|
A table used in this query
CREATE TABLE “MARKS”
( “IDX” NUMBER,
“NAME” VARCHAR2(100),
“CN” NUMBER,
“CA” NUMBER,
“CG” NUMBER,
“CO” NUMBER,
“OS” NUMBER
)
Oracle SQL Statement
SELECT NAME,
SUM(CASE WHEN idx=1 THEN CN+CA+CG+CO+OS END) TOTAL
FROM MARKS
GROUP BY NAME
MS SQL Server Statement
SELECT NAME,
SUM(CASE WHEN idx=1 THEN CN+CA+CG+CO+OS END) AS TOTAL
FROM MARKS
GROUP BY NAME