我有这种方式的数据
ID SUB Marks
1 English 25
1 Maths 22
1 Science 15
2 English 16
2 Maths 20
2 Science 12
等等...
我将如何总结所有科目分数并给出每个 ID 的总分?
例如,如果我选择 ID=1,那么它应该显示 62。
这应该这样做:
SELECT ID, SUM(Marks) as totalMarks
FROM MyTable
GROUP BY Id
select id, sum(Marks) as marks
from tablename
group by id
试试这个……这行得通……
SELECT ID, SUM(Marks) as Total
FROM Table_Name
GROUP BY ID
ORDER BY ID