参考链接
https://blog.youkuaiyun.com/dyzhen/article/details/44803171
https://www.cnblogs.com/acm-bingzi/p/msqlLimit.html
MySQL的limit
limit是mysql的语法,很方便
1. select * from table limit n
取前n行数据。
2. select * from table limit m,n
排除掉前m行数据,然后取n行数据,即取m+1至m+n行的数据
3. select * from table limit m,-1
排除掉前m行数据,然后取到最后,即取m+1至最后一行的数据
Oracle的rownum
rownum是oracle系统顺序分配为从查询返回的行的编号
1.取前n行数据
select * from table where rownum<n
tips: select * from table where rownum>n是错误的,rownum不能大于或者等于
2.取第n行数据
select * from (select rownum r, t.* from table t) where r=n
不过这样速度较慢,因为只取第n行数据,因此可以在括号里做限制:
select * from (select rownum r, t.* from table t where rownum<n+1) where r=n
3.取第m至n行数据
select * from (select rownum r, t.* from table t where rownum<=n) where r>=m
4.返回最后一行记录
select * from (select rownum r, t.* from table t) where r=(select count(*) from table)
5.返回最后n行记录
select * from (select rownum r, t.* from table t) where r>(select count(*)-n from table)