编码过程中遇到的SQL分页情况,总结:
从数据库表中第M条记录开始检索N条记录
MySQL:
先查询分页,然后排序:
select * from (select * from student limit 5,2) pageTable order by id desc ;
先排序,然后查询分页:select * from student order by id desc limit 5,2 ;
Oracle:
SELECT * FROM (SELECT ROWNUM r,t1.* From 表名称 t1 where rownum < M + N) pageTable where t2.r >= M;
SELECT * FROM (SELECT ROWNUM r,s.* From student s where rownum < 7) pageTable where t2.r >= 5