赞
踩
Mysql使用的是limit关键字进行分页查询(这个是Mysql数据库的方言),Oracle数据库使用rownum进行分页查询
1.Mysql使用limit分页
①基础格式:
select* from 表名 limit 起始位置,每页条数
②计算公式:
起始位置=(当前页数-1)*每页条数
③举例:每页显示5条,从第6页开始
select* from stu limit 25,5 --(6-1)*5=25
①Oracle数据库没查询出一行记录,就会在改行上加一个rownum,总之rownum要加在select操作后面
举例:
select rownum,e.* from emp e
②当执行了排序操作后,rownum的顺序会打乱
举例:
select rownum ,e.* from emp e order by e.sal desc
③如果涉及到排序,但是还要使用rownum,就需要使用嵌套查询
select rownum,t.* from(
select rownum,e.* from emp e order by e.sal desc
)t;
–emp表工资倒叙排列后,每页5条记录,查询第二页(完成这个题就可以完成分页查询)
select * from(
select rownum rn,e.* from(
select * from emp order by sal desc
)e where rownum <11
)where rn >5
要完分页查询,需要使用三层嵌套,这是一个标准格式!!
注意:
1.rownum不能跳着走
2.这样写分页是错误的,rownum不能接着写大于正数
select rownum, e.* from(
select * from emp order by sal desc
)e where rownum >11 and rownum <5
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。