Sql-ex.ru - 练习23

时间:2016-11-02 16:31:19

标签: mysql sql

目前停留在上面的问题上,我正在使用的代码当前正在生成正确的答案,但我得到的是“您的查询在第一个(可用的)数据库上返回了正确的数据集,但它返回了不正确的数据集第二个检查数据库。“信息。以下是我正在使用的内容:

SELECT DISTINCT a.maker
FROM (
SELECT maker, product.model
FROM product
JOIN pc
ON product.model=pc.model
WHERE pc.speed>=750
) AS a
LEFT JOIN (
SELECT maker, product.model
FROM product
JOIN laptop
ON product.model=laptop.model
WHERE laptop.speed>=750
) AS b
ON a.model=b.model

问题是:让制造商生产速度为750 MHz或更高的PC和速度为750 MHz或更高的笔记本电脑。我正在加入两张包含我所追求的产品的表格,并将其作为制造商输出。怎么告诉我这是不对的?

2 个答案:

答案 0 :(得分:1)

你可以在没有加入的情况下完成:

select maker from
Product
where model IN(select model from laptop where speed>=750) 

INTERSECT

select maker from
Product
where model IN (select model from PC where speed>=750)

答案 1 :(得分:0)

这对我有用:

SELECT Product.maker
FROM Product
INNER JOIN PC
ON Product.model = PC.model
WHERE PC.speed>=750
INTERSECT
SELECT Product.maker
FROM Product
INNER JOIN Laptop
ON Product.model = Laptop.model
WHERE Laptop.speed>=750