Home > Database > Mysql Tutorial > body text

oracle的Top n时排序问题

WBOY
Release: 2016-06-07 15:44:30
Original
1456 people have browsed it

在 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”来取得 top n的记录,但当使用 order by关键字进行排序时就有问题了(可以试试)。

如下sql script:

 

select  [column] from [table_name] where rownum5
   order by [column] desc 

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!