create cursortmp(id int,name varchar(10))
insert into tmp(id,name) values(10,'01')
insert into tmp(id,name) values(10,'01')
insert into tmp(id,name) values(10,'01')
insert into tmp(id,name) values(10,'01')
insert into tmp(id,name) values(20,'02')
insert into tmp(id,name) values(20,'02')
insert into tmp(id,name) values(20,'02')
insert into tmp(id,name) values(20,'02')
insert into tmp(id,name) values(20,'02')
insert into tmp(id,name) values(30,'03')
insert into tmp(id,name) values(30,'03')
insert into tmp(id,name) values(30,'03')
select sum(id) as id,name from tmp
group by name having sum(id)>80
**好像 group by 要放在 having 前面
结果为
id
name
100
02
90
03
[此贴子已经被作者于2016-5-23 11:52编辑过]