对于给定的数据库
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
问题是: 在 RAM 最低的 PC 中找到同时生产 RAM 最低、处理器速度最快的 PC 的打印机制造商。结果集:制造商。
让我们拆分查询!
- 查找也生产 PC 的打印机制造商
SELECT DISTINCT maker from product Group By maker,type HAVING type IN('Printer','PC')
我认为这是错误的,因为 IN('Printer','PC') 就像 OR not AND
- 具有最低 RAM 的 PC
SELECT model,speed FROM pc WHERE ram=(SELECT MIN(ram) FROM pc) aslowestRam
- 具有最低 RAM 的 PC 中速度最快的处理器
WHERE lowestRam.speed=(SELECT MAX(speed) FROM pc WHERE ram=(SELECT MIN(ram) FROM pc))
查询自己!
SELECT DISTINCT maker FROM
(SELECT DISTINCT model,speed FROM pc WHERE ram=(SELECT MIN(ram) FROM pc)) as lowestRam
INNER JOIN product
ON product.model=lowestRam.model
WHERE
lowestRam.speed=(SELECT max(speed) FROM pc WHERE ram=(SELECT MIN(ram) FROM pc))
Group By maker,type HAVING type IN( 'Printer' ,'PC')
不幸的是,当我在检查站点上提交查询时,它会产生 1 个额外的错误结果:(
问题来自Link。查询验证有 2 个步骤。第二步仅显示用户和正确结果之间的差异:(