22,210
社区成员
发帖
与我相关
我的任务
分享
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 行受影响)
*/