如果我有以下数据:
Policy Number: Amount:
100 200
100 100
101 50
102 90
我可以在SQL代码中编写什么来获得以下结果而不更改数据
Policy Number: Amount:
100 300
101 50
102 90
答案 0 :(得分:2)
您只需要按非聚合列进行分组:
select
[Policy Number],
sum(Amount)
from the_table
group by [Policy Number]
答案 1 :(得分:1)
SELECT PolicyNumber, SUM(Amount) FROM Table GROUP BY PolicyNumber
答案 2 :(得分:1)
Select policy_number, sum(amount) as amount
from table_name
group by policy_number
order by 1