select id, name, sum(num)num from tb group by id,name
是显示,还是统计?如果是显示的时候相同数据只显示一行就行了,select id , name , sum(num) num from tb group by id , name
如果是想插入时就这么做,比较麻烦了. declare id as varchar(2) set @id = '01' if exists (select 1 from tb where id = @id) update tb set num = num + 11 where id = @id else insert into tb select @id , 'name' , 11
select id , name , sum(num) num from tb group by id , name
name,
sum(num)num
from tb
group by id,name
declare id as varchar(2)
set @id = '01'
if exists (select 1 from tb where id = @id)
update tb set num = num + 11 where id = @id
else
insert into tb select @id , 'name' , 11