数据库分页

对于SqlServer 数据库 如要到得第1000-1010条记录:

Select top 10  * from (

Select top 10  * from (

     Select top 1010 * from docdetail order by lastmodidate asc ,Id asc 

) temptbl1 order by lastmodidate desc ,Id desc 

) temptbl2 order by lastmodidate asc,Id asc 

对于oracle 数据库 如要到得第1000-1010条记录 由于oracle中的rownum是在查询之后排序之前赋值的.所以其相应的写法应为:
 select * from ( 

         select my_table.*, rownum as temptbl_rownum from ( 

                   Select * from docdetail order by lastmodidate asc,Id asc 

      ) temptbl where rownum <1010 

 ) where  temptbl_rownum >=1000 

当以上的Sql语句执行完成以后, 网络传输数据量就从以前的1010条减少到 10条
通过以上分页方式的改变,对我们系统的性能有很大的提升
我有个客户使用的是oracel数据库 其中文档数目为 12万条 ,当我们对这张表时行搜索的时候 使用第一种方法进行分页时,页面显示的时间约为10秒左右,而使用第三种方法而现在页面显示时间只需要2-3秒左右. 

当然,可能还有更好的分页方法,总觉得随着数据库里的数据的不断增加,系统运行的速度将会变慢,我在这里贴出这篇文章,只是想和大家讨论一下,还有没有更好的方法, 希望大家不吝回复! 一起讨论!
:D (完)

随便说说 发表于2005-04-14 2:42 PM 
1.
select my_table.*, rownum as temptbl_rownum from (
Select * from docdetail order by lastmodidate asc,Id asc
) temptbl where rownum <1010 and rownum >=1000

2.
select * from docdetail rownum <1010
minus
select * from docdetail rownum <1000

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值