此选择应适用于任何值:
select distinct status
from a a1
where (select count(distinct id) from a) = (select count(distinct id) from a a2 where a2.status = a1.status)
这是一个完整的脚本,适用于您问题中的示例数字:create table a (id int, status int)
insert a values (11, 0)
insert a values (11, 1)
insert a values (11, 2)
insert a values (12, 0)
insert a values (12, 1)
insert a values (12, 2)
insert a values (13, 1)
insert a values (14, 2)
select distinct status
from a a1
where (select count(distinct id) from a) = (select count(distinct id) from a a2 where a2.status = a1.status)
delete a where id = 14
select distinct status
from a a1
where (select count(distinct id) from a) = (select count(distinct id) from a a2 where a2.status = a1.status)
delete a where id = 13
select distinct status
from a a1
where (select count(distinct id) from a) = (select count(distinct id) from a a2 where a2.status = a1.status)