Reputation: 93
I am new to MYSQL and need a simple query but can't get it to work.
I have a table
id amount
1 30
2 20
3 30
3 30
4 50
I want the sum of the amount for distinct ids
So the output should simply be 130. (30+20+30+50)
How can I achieve this ?
Thanks.
Upvotes: 1
Views: 1253
Reputation: 64466
You can use distinct
select sum(amount) from (
select distinct `id`, `amount` from t
) t1
or pick the max amount for same ids
select sum(amount) from (
select `id`, max(`amount`) amount from t group by id
) t1
Upvotes: 1