十大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 联系我们: