数据库分页操作

1、Oracle数据库:

A.select * from ( select a.*, rownum rn from (select * from table) a where rownum <= 40 ) where rn >= 21

B.select * from ( select a.*, rownum rn from (select * from table) a ) where rn between 21 and 40

C.select a.* from (select *,rownum rn from table where rownum <=5) a where rn >=3; 

例:select * from ( select t.*,rownum rn from ( select * from table) t where rownum<=(pageno*pagesize) )where rn>(paegno-1)*pagesize

2、MySQL数据库

A.select * from table limit 10,20

例:select * from table limit (pageno-1)*pageSize,pageno*pageSize

3、SqlServer数据库

A.select * from ( select *, row_number() over(order by id ) as id from table) as b where id between 10 and 20 

B.select b.* from (

select top 10 a.* from (

select top 20 * from table order by id asc ) -- 其中里面这层,必须指定按照升序排序,省略的话,查询出的结果是错误的。
as a order by a.id desc ) b order by b.id asc

C.select * from table order by id offset 4 rows fetch next 5 rows only(SQL2012以上的版本才支持:推荐使用 )

例:select b.* from (select top (pageno-1)*pageSize a.* from (select top pageno*pageSize * from table order by id asc) a order by a.id desc ) b order by b.id asc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值