Reputation: 43
below is the table i have created, my goal is to remove the duplicate results then add the value up.
| username | value
| Bobby | 5
| Bobby | 5
| Bobby | 7
This is the result I am looking for
| username | value
| Bobby | 12
How can I achieve this?
Upvotes: 0
Views: 81
Reputation: 553
Here's simpler way
SELECT distinct(username), sum(distinct value) AS Value from temp1
It works for sure
Upvotes: 0
Reputation: 3856
please try this
select username,sum(value) from
(
select username,value from tbl group by username,value
)data
group by name
Upvotes: 0
Reputation: 4629
Try this
select username, sum(value) from
(select distinct username,value from mytbl) as tmp group by username
Upvotes: 1