在我的sql中使用Distinct和Sum

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?

SELECT SUM(DISTINCT value) FROM TableName Group By UserName

Try this

select username, sum(value) from 
(select distinct username,value from mytbl) as tmp  group by username

please try this

 select username,sum(value) from 
 (
   select username,value from tbl group by username,value
 )data
  group by name

Here's simpler way

SELECT distinct(username), sum(distinct value) AS Value from temp1

It works for sure