我有以下关系
Supplies
sid 1 2 3 4
sname Jason David John Peter
address 1a 2b 3c 4d
Parts
pid 10 20 30 40 50
pname Head Body Hand Leg Arm
color red blue green white red
Catalog
sid 1 1 2 2 3 4 1 1 4 4 1
pid 10 20 20 30 30 40 30 40 10 50 50
cost 100 200 150 150 130 125 50 180 123 126 120
我想选择供应每个红色或绿色部分的供应商的 sid。我认为这意味着it not exist that green or red parts that not supplied by him.
所以我做了以下查询,但它返回 null,我认为它应该返回 sid 为 1。
SELECT S.sid
FROM Suppliers S
WHERE NOT
EXISTS (
SELECT P.pid
FROM Parts P
WHERE P.color = 'red' OR P.color = 'green'
AND NOT
EXISTS (
SELECT C.pid
FROM Catalog C
WHERE C.pid = P.pid
AND C.sid = S.sid
)
)
我如何解决它?预先感谢。