oracle中rownum的使用

rownum是系统的一个关键字,表示行号,是系统自动分配的,第一条符合要求的数据行号就是1,第二条符合要求的数据行号就是2.

Rownum 不能直接使用

例:取前多少条数据:

select * from emp e where rownum <= 5

 

取中间的一些数据:

select * from (select e.*, rownum rn from emp e) t01

 where t01.rn >= 6 and t01.rn <= 10

 

不能直接select * from emp e where rownum >= 6 and rownum<=10; 这样是错误的!

取出 薪资最高的 6~10名员工:

select * from (select e.* from emp e order by e.sal desc) t01

 where t01.rn >= 6 and t01.rn <= 10

 

mysql中使用

Select * from tablename limit startrow(0是第一行),pagesize

例:

Select * from t_address_province limit 0,5;

 

posted @ 2019-04-16 20:33  J-boya  阅读(230)  评论(0编辑  收藏  举报