MySql实现分页

--升序 ase
select 
   info.id,info.age,info.address 
from test.info 
where 
  info.id>=
  (
    select 
      info.id 
    from 
      test.info 
    where 
      info.id > 0 
    order by 
      info.id asc limit 12,1 -- offset=12, 第4页
  ) 
and 
  info.id > 0 
order by info.id asc limit 3 -- page size

--降序desc
select 
    info.id,info.age,info.address 
from test.info 
where 
  info.id<=
  (
    select 
      info.id 
    from 
      test.info 
    where 
      info.id < 100 order by info.id desc limit 12,1 -- offset=12, 第4页
   ) 
and 
  info.id < 100 
order by info.id desc limit 3 -- page size

 

你可能感兴趣的:(mysql)