我有一张包含以下数据的表格:
Account number Amount
13 40
34 30
14 30
13 60
14 10
我想知道如何编写查询以返回以下结果
Account number Total amount
13 100
14 40
34 30
查询应计算共享相同帐号的金额列中所有金额的总和。
非常感谢任何帮助!
答案 0 :(得分:0)
请尝试:
select
[Account Number],
sum(Amount) Amount
from
YourTable
Group by [Account Number]
答案 1 :(得分:0)
使用Group By
+ SUM
SELECT [Account number],
SUM(Amount) As [Total Amount]
FROM dbo.Table1
GROUP BY [Account Number]
ORDER BY SUM(Amount) DESC