1.Oracle,MySQL,sqlServer写法的异同点,分页功能
MySQL用limit分页
select * from (select * from Student) limit 0,20; //取1-20条数据
select * from (select * from Student) limit 20,20; //取21-40条数据
第二种 写法
select * from Student where limit (currentPage-1)*pageSize ,pageSize;
oracle用ROWNUM分页
select * from(select a.*,ROWNUM rn from(sql) a where ROWNUM<=(firstIndex+pageSize)) where rn>firstIndex
eg: select * from(select a.*,ROWNUM rn from(select * from Student order by id asc) a where ROWNUM<=20) where rn>0 // 取1-20条数据
select * from(select a.*,ROWNUM rn from(select * from Student order by id asc) a where ROWNUM<=(20+20)) where rn>20 // 取21-40条数据
第二种写法
select * from ( select rownum rn,t.* from Student t where rownum <= currentPage*pageSize ) where rownum > (currentPage -1)*pageSize;
SqlServer用top分页
select top pageSize o.* from (select row_number() over(order by orderColumn) as rownumber,* from(sql)) as o where rownumber>firstIndex;
eg: select top 20 o.* from (select row_number() over(order by id asc) as rownumber,* from(select * from Student)) as o where rownumber>0; // 取1-20条数据
第二种写法
select top pageSize * from Student where id not in (select top (currentPage-1)*pageSize id from Student) ;
————————————————
版权声明:本文为CSDN博主「疯狂的小鱼」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/longmapang/article/details/53695730