Sum of multiple rows in MySql

I have data this way

ID SUB Marks 1 English 25 1 Maths 22 1 Science 15 2 English 16 2 Maths 20 2 Science 12 

And so on...

How can I summarize all labels of objects and give general estimates of each identifier?

For example, if I select ID = 1, then it should show 62.

+4
source share
3 answers
 select id, sum(Marks) as marks from tablename group by id 
+6
source

This should do it:

 SELECT ID, SUM(Marks) as totalMarks FROM MyTable GROUP BY Id 
+6
source

Try this ... it works ...

 SELECT ID, SUM(Marks) as Total FROM Table_Name GROUP BY ID ORDER BY ID 
+2
source

Source: https://habr.com/ru/post/1433640/


All Articles