分页查询
MySQL分页,关键字limit
示例:
--select * from 表名 where 限制条件 limit num1(start),num2(size);
Oracle分页,关键字rownum
示例1:
select ename,rownum from emp;
select ename,rownum from (select * from emp);
示例2:(三层过滤,效率较高):
select t2.* from (select t1.*, rownum rn from (select * from emp)t1 where rownum<=6)t2 where rn>=4;
--第一层:
--select * from emp ..
--第二层:
--select * from (第一层) where rownum <=6(endNum);
--第三层:
--select * from (第二层) where rownum >=4(startNum);
示例3:按照入职时间的顺序,查询从第7个到第10个人
select t2.* from (select t1.*, rownum rn from (select * from emp order by hiredate)t1 where rownum<=10)t2 where rn>=7;
参考:http://www.linuxidc.com/Linux/2013-01/78288.htm