数据库模式
问题 -
找出制造商 B 生产的所有产品(任何类型)的型号和价格。
我的尝试——
SELECT b.model, b.price FROM laptop AS b
WHERE b.model IN ( SELECT model FROM product WHERE maker = 'B')
UNION
SELECT c.model, c.price FROM pc AS c
WHERE c.model IN ( SELECT model FROM product WHERE maker = 'B')
UNION
SELECT d.model, d.price FROM printer AS d
WHERE d.model IN ( SELECT model FROM product WHERE maker = 'B')
即使这也没有显示仅使用 B 的正确数据集 -
SELECT b.model, b.price FROM laptop AS b
WHERE b.model IN ( SELECT model FROM product WHERE maker = 'B')
只有一个结果集即将到来。
让我知道我在查询时犯的逻辑错误。
编辑 -
输出 -
SELECT model FROM product WHERE maker = 'B'
SELECT b.model, b.price FROM laptop AS b
WHERE b.model IN ( SELECT model FROM product WHERE maker = 'B')
询问 -SELECT * FROM product WHERE maker = 'B'
输出 -