0

Is it possible to display only 20 items of the whole result? I know of a query "rownum>=20" but that only makes the sql check only the first 20 rows in the table. But i want the sql to check my whole table and display only the highest 20 entries.

To be clear, I have a table with job description like Title, description, agency, salary_min, salary max. I want to display the 20 highest paying jobs.

4

4 回答 4

4

“最高”的 20 个条目表明了一种排序。你会做这样的事情:

select t.*
from (select t.*
      from table t
      order by highestcol desc
     ) t
where rownum <= 20;

如果您使用的是 Oracle 12g 或更新版本,则可以改用该fetch first子句:

select t.*
from table t
order by highestcol desc
fetch first 20 rows only;
于 2014-11-27T04:24:58.167 回答
1

首先 sort(order by) 然后使用 rownum 函数。

于 2014-11-27T04:24:06.407 回答
1
select * from  
( select * 
  from emp 
  order by field ) 
where ROWNUM <= 20;
于 2014-11-27T04:24:23.087 回答
1
select a.fld1, a.fld2 
from 
  ( select fld1, fld2
    from mytable 
    order by 1 desc) a
where rownum <21;

这是我认为您要求的一种方法。还有其他一些海报可以提供的其他方式。

于 2014-11-27T04:27:03.603 回答