SUM of Multiple columns of MySQL table

Last Reply on Jun 27, 2014 04:02 AM By Azim

Posted on Jun 27, 2014 04:01 AM

NAME  X    Y
A       10  20

B        12  24 

C        15  22 

D         18  9

i want to get name of students group by their total marks in desc order

Posted on Jun 27, 2014 04:02 AM

This way


DECLARE @tblStudent TABLE (NAME VARCHAR(20), Subject1 INT, Subject2 INT)
INSERT INTO @tblStudent VALUES('A',10,20)
INSERT INTO @tblStudent VALUES('B',12,24)
INSERT INTO @tblStudent VALUES('C',15,22)
INSERT INTO @tblStudent VALUES('D',18,9)
SELECT Name, Subject1 + Subject2 as Total FROM @tblStudent ORDER By Total DESC


Name Total

C         37
B         36
A         30
D         27

I agree, here is the link: