Reputation: 123
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!
Upvotes: 2
Views: 4227
Reputation: 460278
Use Group By
+ SUM
SELECT [Account number],
SUM(Amount) As [Total Amount]
FROM dbo.Table1
GROUP BY [Account Number]
ORDER BY SUM(Amount) DESC
Upvotes: 2
Reputation: 18659
Please try:
select
[Account Number],
sum(Amount) Amount
from
YourTable
Group by [Account Number]
Upvotes: 0