我正在努力寻找那些只生产笔记本而不是PC的产品的制造商
Relations:
Product(maker, model, type)
Laptop(Model, price, speed, ram, hd, screen)
PC(model, price, speed, ram, hd)
Printer(model,price, color, price)
我尝试了什么
(SELECT maker, type
FROM product WHERE type = 'laptop')
DIFFERENCE
(SELECT maker, type
FROM product WHERE type = 'pc');
我认为它在MySQL中没有差异操作?
答案 0 :(得分:2)
SELECT
p1.maker,
p1.type
FROM
product p1
LEFT JOIN product p2 ON p2.maker = p1.maker AND p2.type = 'pc'
WHERE
p1.type = 'laptop'
p2.maker IS NULL
答案 1 :(得分:1)
SELECT maker, type FROM product WHERE type = 'laptop' AND type != 'pc';
答案 2 :(得分:1)
select maker, type from product
where type='laptop' and
maker not in (select maker from product where type = 'pc')
答案 3 :(得分:0)
SELECT `maker`, `type` FROM `product` WHERE `type` = 'laptop' AND `maker` NOT IN
(SELECT `maker`, `type` FROM `product` WHERE `type` = 'pc');
答案 4 :(得分:-1)
SELECT p.maker, p.type
FROM product p
WHERE p.type = 'laptop'
AND NOT EXISTS (
SELECT p2.maker, p2.type
FROM table p2
WHERE p2.type = 'pc'
AND p2.maker = p1.maker
)