我正在尝试返回没有经理的分支机构。
这就是我的尝试:
SELECT branchno, city FROM branch
WHERE branchno IN
(SELECT branchno FROM STAFF
WHERE position <> 'Manager');
它返回:
branchno | city
----------+----------
B005 | London
B007 | Aberdeen
B003 | Glasgow
(3 rows)
答案 0 :(得分:1)
您可以使用not in
select *
from branch
where branchno not in (
select branchno from staff
where position = 'Manager'
);
答案 1 :(得分:1)
有很多方法,您可以使用下面的WHERE NOT EXISTS
。顺便说一下,您发布的查询也应该为您提供所需的结果(根据您的帖子标题)。你还在寻找什么?
SELECT b.branchno, b.city
FROM branch b
WHERE NOT EXISTS
(SELECT 1 FROM STAFF WHERE branchno = b.branchno
AND position = 'Manager');