倪彼情感
您的当前位置:首页oracle的Topn时排序问题

oracle的Topn时排序问题

来源:倪彼情感


在 oracle 中使用 SQL 查询时, 可以用“ rownumn ”来取得 top n 的记录,但当使用 order by 关键字进行排序时就有问题了(可以试试)。 如下 sql script: 【 select [column] from[table_name] where rownum= 5 order by[column] desc 】 当使用 order by

在oracle 中使用SQL查询时,可以用“rownum

如下sql script:

【 select [column] from [table_name] where rownum<=5
order by [column] desc

当使用order by时应写成:
select [column] from
(select [column] from [table_name]
order by [
column] desc) where rownum <= 1

显示全文