How to add column values in mysql

Trialcoder picture Trialcoder · Sep 12, 2012 · Viewed 95.5k times · Source

This is my table data Student

enter image description here

And this is my query --

SELECT id, SUM( maths + chemistry + physics ) AS total, maths, chemistry, physics
FROM `student`

but it is throwing a single row --

id  total   maths   chemistry   physics
118     760     55  67  55

although i want to apply sum for all ids ....let me know how can i achieve this?

Answer

Piyu picture Piyu · Sep 12, 2012

Sum is a aggregate function. You dont need to use it. This is the simple query -

select *,(maths + chemistry + physics ) AS total FROM `student`