17,082
社区成员
发帖
与我相关
我的任务
分享
update test set status=0 from test t1
where exists(select 1 from test t2 where t1.id=t2.id and t1.status<>t2.status)
go
select distinct * from test
/*
ID STATUS
----------- -----------
1 2
2 0
3 0
4 1
*/
select id,
case when max(status)=1 and min(status)=1 then 1
when min(status)=2 then 2 else 0 end status
from test
group by id