4

我正在努力寻找只生产笔记本电脑而不生产个人电脑的产品制造商

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中没有区别操作?

4

5 回答 5

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
于 2012-04-03T21:59:02.927 回答
1

SELECT maker, type FROM product WHERE type = 'laptop' AND type != 'pc';

于 2012-04-03T21:56:35.767 回答
1
select maker, type from product 
where type='laptop' and
maker not in (select maker from product where type = 'pc')
于 2012-04-03T21:59:08.717 回答
0
SELECT `maker`, `type` FROM `product` WHERE `type` = 'laptop' AND `maker` NOT IN
                 (SELECT `maker`, `type` FROM `product` WHERE `type` = 'pc');
于 2012-04-03T22:00:38.420 回答
-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
    ) 
于 2012-04-03T21:54:53.213 回答