SQL查询如何实现数据分页?
- 内容介绍
- 文章标签
- 相关推荐
本文共计207个文字,预计阅读时间需要1分钟。
1. 使用ROWID筛选特定记录的SQL查询 查询t_xiaoxi表中,根据rowid范围获取数据,并按cid降序排列。执行时间为0.03秒。
2. 基于分析函数的查询 查询中使用了分析函数来处理数据。
1.根据ROWID来分
select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from
t_xiaoxi order by cid desc) where rownum<10000) where rn>9980) order by cid desc;
执行时间0.03秒
2.按分析函数来分
select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t) where rk<10000 and rk>9980;
执行时间1.01秒
3.按ROWNUM来分
select * from(select t.*,rownum rn from(select * from t_xiaoxi order by cid desc) t where rownum<10000) where
rn>9980;执行时间0.1秒
其中t_xiaoxi为表名称,cid为表的关键字段,取按CID降序排序后的第9981-9999条记录,t_xiaoxi表有70000多条记录
个人感觉1的效率最好,3次之,2最差
本文共计207个文字,预计阅读时间需要1分钟。
1. 使用ROWID筛选特定记录的SQL查询 查询t_xiaoxi表中,根据rowid范围获取数据,并按cid降序排列。执行时间为0.03秒。
2. 基于分析函数的查询 查询中使用了分析函数来处理数据。
1.根据ROWID来分
select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from
t_xiaoxi order by cid desc) where rownum<10000) where rn>9980) order by cid desc;
执行时间0.03秒
2.按分析函数来分
select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t) where rk<10000 and rk>9980;
执行时间1.01秒
3.按ROWNUM来分
select * from(select t.*,rownum rn from(select * from t_xiaoxi order by cid desc) t where rownum<10000) where
rn>9980;执行时间0.1秒
其中t_xiaoxi为表名称,cid为表的关键字段,取按CID降序排序后的第9981-9999条记录,t_xiaoxi表有70000多条记录
个人感觉1的效率最好,3次之,2最差

