34,590
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([字段1] varchar(4),[字段2] int,[字段3] int)
insert [tb]
select 'asd',1,1 union all
select 'asd',2,1 union all
select 'abas',2,1 union all
select 'zxc',1,2 union all
select 'df',1,1 union all
select 'asd',2,1
select * from [tb]
select [字段1] from tb
where [字段3]=1
group by [字段1]
having sum([字段2])>4
/*
[字段1]
------
asd
*/
select col1,sum(col2) from TA where col3=1
group by col1 having sum(col2)>4