我在这里有一个问题: 对于美国的每个国家,给出最高的山峰和高度;按高度排序。 和表格:
encompasses : country,continent
geo_mountain: mountain,country
mountain:name,height
我写道:
select co.country,mo.name, max(mo.height) as mheight
from mountain mo,encompasses co
join geo_mountain gmo
on mo.name=gmo.mountain
where gmo.country=any (select country from encompasses where continen='America')
GROUP BY co.country
order by mheight;
但我在oracle 11g中遇到此错误:
Error at Command Line:203 Column:4(second like)
SQL Error: ORA-00904: "MO"."NAME": invalid identifier
答案 0 :(得分:4)
问题在于您正在混合JOIN语法 - 您正在使用显式和隐式语法。显式JOIN具有更高的优先级,因此隐式连接(mountain
,encompasses
)中的表的别名不可用。如果要执行交叉连接或笛卡尔结果,则应使用:
select co.country,
mo.name,
max(mo.height) as mheight
from mountain mo
cross join encompasses co
join geo_mountain gmo
on mo.name=gmo.mountain
where gmo.country=any (select country
from encompasses
where continent ='America')
GROUP BY co.country, mo.name
order by mheight;
答案 1 :(得分:-1)
尝试在完整的表名而不是别名上进行连接... 在mountain.name = geo_mountain.mountain
还要记住,Oracle区分大小写(至少在我上次使用它时)。 您也可以在连接字段上进行上限转换。