表:
Classes (class, type, country, numGuns, bore, displacement)
Ships (name, class, launched)
Outcome (ship, battle, result)
问题:
为每个等级找出该等级在战斗中沉没的船只数量。
我的答案:
SELECT ships.class, COUNT(*)
FROM ships, outcome
WHERE ships.name = outcomes.ship AND outcome.result = 'sunk'
GROUP BY ships.class
加入回答:
SELECT class, COUNT(*)
from ships
inner join outcomes
on name = ship
where outcome.result = 'sunk'
group by class
样本手册中给出的答案:
SELECT classes.class, COUNT(*)
FROM classes, ships, outcomes
WHERE classes.class = ships.class AND ship = name AND result = 'sunk'
GROUP BY classes.class;
我不明白为什么他们必须包含classes
表格,我的查询还不够吗?我正在做同样的事情,但没有加入classes
桌子。提前致谢。