我有下表:
'committee' table
commname profname
========================
commA bill
commA jack
commA piper
commB bill
commB piper
我正试图找到“吹笛者”所在的每个委员会中的教授
(答案应该是 Piper 和 Bill):
我有以下 SQL 除法查询,但它是错误的,我无法弄清楚问题出在哪里(不返回账单,只返回 Piper):
select b.profname
from committee b
where not exists
(select commname
from committee a
where profname = 'piper' and not exists
(select commname
from committee
where a.profname=b.profname ))
有人可以帮我解决这个问题吗?
谢谢,
最里面的 select 在其 where 子句中不使用自身的任何内容,因此它总是为 Piper 找到一些东西。尝试
select distinct b.profname from committee b
where not exists (
select commname from committee a
where a.profname = 'piper' and not exists (
select commname from committee c
where c.profname=b.profname and c.commname=a.commname
)
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)