qn:查找仅提供绿色部件的供应商名称
答案 0 :(得分:1)
不知道你是如何存储颜色的(即HTML颜色定义,名称或内容),但像这样的查询可能会起到作用:
select supplier.name
from supplier
where supplier.sid in (
-- all the suppliers who supply green parts
select distinct(a.sid)
from catalog a
inner join parts b on a.pid = b.pid
where b.color = 'green')
and supplier.sid not in (
-- all the supplier ids who supply parts that are not green
select distinct(a.sid)
from catalog a
inner join parts b on a.pid = b.pid
where b.color <> 'green')
这将返回仅包含绿色部件的供应商名称。
答案 1 :(得分:0)
从目录中选择supplier.sid,supplier.sname,supplier.Address,其中part.color ='green'left join supplier on(catalog.sid = supplier.sid) 左连接部分(catalog.pid = parts.pid);