Reputation: 600
If I have the following data:
Policy Number: Amount:
100 200
100 100
101 50
102 90
What can I write in SQL code to get the following result without changing the data
Policy Number: Amount:
100 300
101 50
102 90
Upvotes: 1
Views: 92
Reputation: 356
Select policy_number, sum(amount) as amount
from table_name
group by policy_number
order by 1
Upvotes: 1
Reputation: 191058
SELECT PolicyNumber, SUM(Amount) FROM Table GROUP BY PolicyNumber
Upvotes: 1
Reputation: 175976
You just need to group-by the non-aggregated column like so:
select
[Policy Number],
sum(Amount)
from the_table
group by [Policy Number]
Upvotes: 2