1、分析函数分页
SELECT xx.* FROM(
SELECT t.*,row_number() over(ORDER BY t.nowprice desc)AS num
FROM auction t where t.status = 0
)xx
WHERE num BETWEEN 1 AND 56;
2、rownum分页
select *
from (select id,
name,
articleid,
nowprice,
count,
asubtype,
asubsubtype,
color,
material,
rownum r
from (select * from auction where status = 0 order by nowprice DESC)
where rownum <= 42)
where r > 0
如果nowprice有相同记录,则 rownum <= 不同的数值,返回的结果不稳定
如果 order by nowprice DESC,id 排序唯一了,则返回结果稳定
rownum与order by的关系
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
![](http://oracle.chinaitlab.com/UploadFiles_7269/200706/20070626110557223.gif)
在检索的时候,会首先把数据检索出来,也就是把EMP表数据都检索出来,然后再Order by排序操作。因为ROWNUM 数据是在排序前就检索出来的了,所以不能利用ROWNUM来取得排序后的前10条操作。那么应该如何操作呢。其实很简单,利用子查询,先排序,再取ROWNUM。