可以这么进行分析 SELECT * from test a where not exists (select * from test b where b.GYSBH='1001' and not exists (select * from test c where b.LJBH=c.LJBH and a.GYSBH=c.GYSBH)) 1。 取出内层 select * from test b where b.GYSBH='1001' and not exists (select * from test c where b.LJBH=c.LJBH and a.GYSBH=c.GYSBH)) 可以分为两个条件 select * from test b where b.GYSBH='1001' and not exists (select * from test c where b.LJBH=c.LJBH) 和 not exists a.GYSBH=c.GYSBH两个条件分别加上前面的Not exists 可以看成被转化为如下两个条件 (1)select * from test b where b.GYSBH='1001' and exists (select * from test c where b.LJBH=c.LJBH)
SELECT * from test a
where not exists (select * from test b where b.GYSBH='1001' and
not exists (select * from test c where b.LJBH=c.LJBH and a.GYSBH=c.GYSBH)) 1。 取出内层
select * from test b where b.GYSBH='1001' and
not exists (select * from test c where b.LJBH=c.LJBH and a.GYSBH=c.GYSBH))
可以分为两个条件
select * from test b where b.GYSBH='1001' and
not exists (select * from test c where b.LJBH=c.LJBH)
和 not exists a.GYSBH=c.GYSBH两个条件分别加上前面的Not exists
可以看成被转化为如下两个条件
(1)select * from test b where b.GYSBH='1001' and
exists (select * from test c where b.LJBH=c.LJBH)
2)exists a.GYSBH=c.GYSBH再综合一下两个条件,很容易得到结果
------------------------------------------------------------------------------------
我觉得是这样:1。找出先找出GYSBH='1001'的所有的LJBH(这里为1,2) 在这里相当于于为B
2。然后A和C得到,每个GYSBH对应的LJBH
3。检查每个GYSBH对应的LJBH是不是包含(1,2)