选择表的最后一行,Oracle 12c

时间:2018-11-25 12:52:09

标签: sql oracle

在此站点上,我找到了sql函数last()LAST() 我为Oracle使用了语法,但出现了一个错误。

SQL> select symbol from ticker
  2  order by price DESC
  3  where rownum <=1;
where rownum <=1
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

我收到一条错误消息,即使命令已正确完成

1 个答案:

答案 0 :(得分:2)

您似乎想要这个:

select t.*
from (select symbol
      from ticker
      order by price DESC
     ) t
 where rownum <= 1;

或者在更现代的Oracle版本中:

select symbol
from ticker
order by price desc
fetch first 1 row only;

或者,如果您想玩得开心:

select max(symbol) keep (dense_rank first order by price desc)
from ticket;

where条件先于order by