数据库查询分页sql

MySQL

 -- 查询第3,4,5行3条数据(第2条开始<不包含第2条>,查询3条数据)
select * from DEMO order by CREATEDATE desc limit 2,3;
select * from DEMO order by CREATEDATE desc limit 3 offset 2;

Oracle

 -- 查询第6行到第10行5条数据(sql1执行效率更好)
 -- sql1
 select ss.*, ss.r
  from (select s.*, rownum as r
          from demo s
         where rownum <= 10) ss
 where ss.r > 5;

-- sql2
select ss.*
  from (select s.*, rownum as r from demo s) ss
 where ss.r > 5
   and ss.r <= 10;

-- sql3
select ss.*
  from (select s.*, rownum as r from demo s) ss
where ss.r between 6 and 10;

你可能感兴趣的:(Mysql,Oracle,基础知识)