日期:2014-05-17 浏览次数:20651 次
create table sq
(id int,producId int,testItem varchar(10),isOk int)
insert into sq
select 1,1001,'Item1',1 union all
select 2,1001,'Item2',0 union all
select 3,1001,'Item3',0 union all
select 4,1001,'Item4',1 union all
select 5,1002,'Item1',1 union all
select 6,1002,'Item2',1 union all
select 7,1002,'Item3',1 union all
select 8,1002,'Item4',1 union all
select 9,1003,'Item1',1 union all
select 10,1003,'Item2',1 union all
select 11,1003,'Item3',1 union all
select 12,1003,'Item4',1
select a.producId,
case when exists(select 1 from sq b
where b.producId=a.producId and isOk=0) then '不合格'
else '合格' end '产品合格情况'
from sq a
group by a.producId
/*
producId 产品合格情况
----------- ------
1001 不合格
1002 合格
1003 合格
(3 row(s) affected)
*/