0
select 
  * 
from 
  (
    select 
      rating, 
      avg(age) as avgage 
    from 
      sailors 
    group by 
      rating
  ) as temp 
where 
  temp.avgage = (
    select 
      min(temp.avgage) 
    from 
      temp
  );

当我尝试运行上述命令时,出现以下错误

ORA-00933: SQL command not properly ended

Sailors 表看起来像这样 Sailors 表

你能告诉我为什么会收到这个错误吗?

4

1 回答 1

3

Oracle 中的表别名没有AS(列可以,但不是必须)。

所以:

No :   ) as temp 
Yes:   ) temp

从 ORA-00942 开始:在子查询temp中无法访问。但是,如果您将它(temp)用作 CTE 或内联视图(以便它是整个查询可读的),那么它应该没问题。像这样的东西:

with temp as
  (select rating, avg(age) as avgage
   from sailors
   group by rating
  )
select *
from temp a
where a.avgage = (select min(b.avgage)
                  from temp b
                 );
于 2021-06-22T14:31:05.367 回答