十大sql查询列表[重复]

[英]Top 10 sql query list [duplicate]


This question already has an answer here:

这个问题在这里已有答案:

Good morning, I need assistance with generating a top 10 list. below is the created query however i'm unsure how to correctly implement the ROWNUM function.

早上好,我需要帮助才能产生前10名。下面是创建的查询,但我不确定如何正确实现ROWNUM功能。

SELECT * FROM
( SELECT CON_NAME, HIGHEST_QUAL FROM temp2 ORDER BY HIGHEST_QUAL DESC )
  WHERE ROWNUM = 10;

As when the query is run no data is produced however when i omit the ROWNUM all the rows are produced showing the data is there. Also when the ROWNUM is set to 1 only one row is produced.

当运行查询时,不会产生任何数据,但是当我省略ROWNUM时,会生成所有行,显示数据在那里。此外,当ROWNUM设置为1时,仅产生一行。

Thanks in advance!

提前致谢!

1 个解决方案

#1


0  

Use ROWNUM inside the subquery and reuse the aliased name with conditions as you like

在子查询中使用ROWNUM,并根据需要重用别名和条件

TOP 10 Highest

前10名最高

   SELECT * FROM
    ( SELECT ROWNUM rnum, CON_NAME, HIGHEST_QUAL FROM temp2 ORDER BY HIGHEST_QUAL DESC )
      WHERE rnum <= 10;

10th Highest

   SELECT * FROM
    ( SELECT ROWNUM rnum, CON_NAME, HIGHEST_QUAL FROM temp2 ORDER BY HIGHEST_QUAL DESC )
      WHERE rnum = 10;

Greater Than Fifth Highest, lesser than 9th Highest

大于第五高,低于第九高

   SELECT * FROM
    ( SELECT ROWNUM rnum, CON_NAME, HIGHEST_QUAL FROM temp2 ORDER BY HIGHEST_QUAL DESC )
      WHERE rnum > 5 and rnum < 9;

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/01/06/afd129a7cded42822106fb46e967d150.html



 
  © 2014-2022 ITdaan.com 联系我们: