我正在尝试创建一个查询,该查询返回另一个表中最多次数的事物的名称和国家/地区。
这是结构:
ShipModels(mname, type, country, numGuns, gunSize)
Ships(sname, hasModel, launchYear)
Battles(bname, year)
Outcomes(ship, battle, result)
我尝试了很多不同的东西,但无法让它发挥作用。这是我当前的查询:
SELECT ship, country
FROM ShipModels, Ships, Outcomes
WHERE hasModel = mname AND ship = sname
GROUP BY ship
HAVING COUNT(ship) >=
( SELECT COUNT (ship) FROM Outcomes GROUP BY ship);
甲骨文错误:
ERROR at line 1:
ORA-00979: not a GROUP BY expression
根据我的阅读,当 SELECT 语句中有聚合函数时会引发此错误,但是......嗯,没有。有什么我想念的吗?我怎样才能让它工作?