这是我的架构:
供应商(sid:整数,sname:字符串,地址字符串)
部分(pid:整数, pname:字符串,颜色:字符串)
目录(sid:整数,pid:整数,成本:实数)
粗体表示主键。
我想写一个查询来查找所有供应每个零件的供应商。这是我已经提出的两个问题:
-- get all parts for a given supplier
SELECT Parts.pid
FROM Suppliers
JOIN Catalog ON Catalog.sid = Suppliers.sid
JOIN Parts ON Parts.pid = Catalog.pid
WHERE Suppliers.sid = 4;
-- gets all parts that exist
SELECT Parts.pid
FROM Parts
用命令式的术语来说,我想做的是这样的:
Define result set
Foreach Supplier:
If the list of parts produced by a supplier
is equal to the total list of parts, add this supplier to the result set
Return result set
我怎样才能把它翻译成 MySQL?