我有下表:
'committee' table commname profname ======================== commA bill commA jack commA piper commB bill commB piper
并且我正在寻找“ piper”所在的每个委员会中的教授(答案应该是吹笛者和账单):
我有以下SQL除法查询,但它是错误的,我无法弄清楚问题出在哪里(不退还账单,只是吹笛者):
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 ))
有人可以帮我吗?谢谢,
您最内在的选择在其where子句中不使用任何内容,因此它总是在寻找一些东西供吹笛者使用。尝试
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 ) );