下面是我创建的表,我的目标是删除重复的结果,然后添加值。
| username | value
| Bobby | 5
| Bobby | 5
| Bobby | 7
这是我正在寻找的结果
| username | value
| Bobby | 12
我怎样才能做到这一点?
答案 0 :(得分:1)
试试这个
select username, sum(value) from
(select distinct username,value from mytbl) as tmp group by username
答案 1 :(得分:0)
SELECT SUM(DISTINCT value) FROM TableName Group By UserName
答案 2 :(得分:0)
请试试这个
select username,sum(value) from
(
select username,value from tbl group by username,value
)data
group by name
答案 3 :(得分:0)
这里更简单
SELECT distinct(username), sum(distinct value) AS Value from temp1
确实有效