全外部自我加入或其他

问题描述 投票:-1回答:2
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。

sql sql-server
2个回答
0
投票

这个问题有点不清楚,但也许这就是你想要的......?

做一个GROUP BY,检查max和min IsVisible = 0。

select MID
from tablename
group by MID
having max(cast(IsVisible as int)) = 0

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
 )
© www.soinside.com 2019 - 2024. All rights reserved.