2

I have a table with the following data in it:

Account number     Amount
13                 40
34                 30
14                 30
13                 60
14                 10

I would like to know how I can write a query to return the following results

Account number     Total amount
13                 100
14                 40
34                 30

The query should calculate the sum of all of the amounts in the amount column that share the same account number.

Any help would be much appreciated!

0

2 Answers 2

2

Use Group By + SUM

SELECT [Account number],
       SUM(Amount) As [Total Amount]
FROM dbo.Table1
GROUP BY [Account Number]
ORDER BY SUM(Amount) DESC

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks heaps for that!
0

Please try:

select
    [Account Number],
    sum(Amount) Amount
from
    YourTable
Group by [Account Number]

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.