一:上码
-- 查询只卖三种不同型号PC的厂商
-- 分析:1.首先 pc和product表联合 字段为厂商
-- 2.统计这些厂商的个数过滤掉型号小于3的厂商 表1
-- 3.然后laptop和product联合 表2,printer和product联合 字段均为厂商 表3
-- 4.将表1作为子表,查询条件为 不在表2和表3中 厂商
-- 1.
-- select maker
-- from pc,product
-- where pc.model = product.model;
-- -- 2.
-- select maker,count(maker)
-- from (select maker
-- from pc,product
-- where pc.model = product.model) as temp
-- group by maker having count(maker) >= 3;
-- -- 3.
-- select maker
-- from laptop,product
-- where laptop.model = product.model;
-- select maker
-- from printer,product
-- where product.model = printer.model;
-- 4.
select maker
from (select maker,count(maker)
from (select maker
from pc,product
where pc.model = product.model) as temp
group by maker having count(maker) >= 3) as temp
where temp.maker not in (select maker
from laptop,product
where laptop.model = product.model)
and temp.maker not in(select maker
from printer,product
where product.model = printer.model);