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;
原文地址:https://www.cnblogs.com/cn-boya/p/10719843.html