关于Oracle分页查询

--MySql,分页

--select * from biaoming where tiaojian limit num1(start),num2(size)

--------Oracle分页,关键字rownum

----

select ename,rownum from emp;

select ename,rownum from (select * from emp);

----三层过滤,效率较高

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);

--按照入职时间的顺序,查询从第7个到第10个人

select t2.* from (select t1.*, rownum rn from (select * from emp order by hiredate)t1 where rownum<=10)t2 where rn>=7;

---------------合并查询

------union

------union all

------intersect

相关推荐