1

I have a table similar to the example below.

Field1 Field2
Chris   100
Chris   200
John    50
Maria   250
John    80

I want to achieve the result shown below.

Chris 300
John  130
Maria 250

I've already achieved this by using 2 separate sql statements. I'm wondering if it can be achieved in a single SQL statement to speed up querying. Thank you very much.

1
  • In what part do you need a COUNT or UNION (as in the title)? That is a SUM only. Maybe add a little more info on what you are trying to do. Commented Dec 11, 2013 at 16:18

2 Answers 2

2

Group by the field you want to sum over and then use sum on the column you want to sum

SELECT Field1, SUM(Field2) as Field2
FROM Mytable
GROUP BY Field1
Sign up to request clarification or add additional context in comments.

Comments

1

Should be able with:

SELECT field1, SUM(field2) FROM table GROUP BY field1

shouldn't it?

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.