日期:2014-05-17 浏览次数:20578 次
SELECT [name],SUM(ISNULL(value,0)) AS Value
FROM tablename
GROUP BY [name] HAVING SUM(ISNULL(value,0))=0
create table #tb
(id int,name varchar(5),value int)
insert into #tb
select 1 ,'a', 0 union all
select 2 ,'b', 0 union all
select 3 ,'b', 1 union all
select 4 ,'c', 0 union all
select 5 ,'c', 0 union all
select 6 ,'a', 1 union all
select 7 ,'a', 0
select name from #tb
group by name having MAX(value)=0
name
-----
c
(1 行受影响)
create table #tb
(id int,name varchar(5),value int)
insert into #tb
select 1 ,'a', 0 union all
select 2 ,'b', 0 union all
select 3 ,'b', 1 union all
select 4 ,'c', 0 union all
select 5 ,'c', 0 union all
select 6 ,'a', 1 union all
select 7 ,'a', 0
select&nbs