This is my table data Student
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?
Tip: If one of the fields has the possibility to be NULL, then use COALESCE to default these to 0, otherwise
total
will result in NULL.You don't need use
SUM
for this operation. Try this query:Sum is a aggregate function. You dont need to use it. This is the simple query -
If you're requiring to get total marks of each student, then
SUM
is not what you'd be needing.Will do the job just fine.
All aggregate function works on rows specified by rowname and group by operation. You need operation on individual rows which is not an option for any aggregate function.
Try this
You are done. Thanks