MID RID Name IsVisible
100 1 AA 1
100 2 AA 0
101 1 BB 1
101 2 BB 1
102 1 CC 0
102 2 CC 0
103 1 DD 0
103 2 DD 1
如何在所有RID中选择IsVisible = 0的不同MID。
对于所有RID,预期结果为102,IsVisible = 0。
这个问题有点不清楚,但也许这就是你想要的......?
做一个GROUP BY
,检查max和min IsVisible = 0。
select MID
from tablename
group by MID
having max(cast(IsVisible as int)) = 0
使用NOT EXISTS
select distinct t1.mid
from your_table t1
where not exists (
select 1
from your_table t2
where t1.mid = t2.mid and t2.isVisible != 0
)