日期:2014-05-17 浏览次数:20547 次
with TEMP(ID,NAME,STATUS) as
(
select 1,'A',0
union all select 2,'A',0
union all select 3,'A',1
union all select 4,'B',1
union all select 5,'B',1
union all select 6,'C',1
)
select min(ID) ID,NAME,max(STATUS) STATUS from TEMP
group by NAME
having min(STATUS)=1
/*
ID          NAME STATUS
----------- ---- -----------
4           B    1
6           C    1
(2 行受影响)
*/