6

I have data in this manner

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 would I sum all subject marks and give total marks of each ID?

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

1
  • There are SQL manuals online if you don't actually want to buy one or take some training, e.g. w3schools.com/sql/default.asp Visit this site and then come back and ask questions if you still can't work these things out. Commented Dec 3, 2012 at 15:32

3 Answers 3

10

This should do it:

SELECT ID, SUM(Marks) as totalMarks
FROM MyTable
GROUP BY Id
Sign up to request clarification or add additional context in comments.

Comments

6
select id, sum(Marks) as marks
from tablename
group by id

Comments

2

Try this... this is working...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.