获取ORA-00918:列模糊定义:运行此SQL:

时间:2017-03-29 20:43:45

标签: sql

SELECT Name AS "Avatar Name", 
       COUNT(WEAPON_ID) AS "Active Weapons Held |", 
       SUM(W.COST) AS "Total Weapons Cost"
FROM   Avatar A, Weapon_Held H, Weapon W
WHERE  A.Avatar_ID=H.AVATAR_ID AND H.WEAPON_ID=W.WEAPON_ID 
Group by Name;

3 个答案:

答案 0 :(得分:3)

首先,从不FROM子句中使用逗号。 始终使用正确的JOIN语法。

其次,使用表别名,但使用无处不在

SELECT Name AS "Avatar Name", 
       COUNT(H.WEAPON_ID) AS "Active Weapons Held", 
       SUM(W.COST) AS "Total Weapons Cost"
FROM Avatar A JOIN
     Weapon_Held H 
     ON A.Avatar_ID = H.AVATAR_ID JOIN
     Weapon W
     ON H.WEAPON_ID = W.WEAPON_ID 
Group by Name;

答案 1 :(得分:0)

这些名为“名称”的表中是否有两个或更多列? 请使用隐式名称,如:'A.Name'或'H.Name',如:

Select A.Name....
Group by A.Name

答案 2 :(得分:0)

您收到错误是因为您的查询中有多个表具有相同的名称,并且不知道从哪里提取它。尝试将您的查询更改为以下内容:

{{1}}