sql 排序分页

  本文介绍oracle/sqlserver数据库分页

  1. Oracle 分页
    1.1 使用伪列 rownum 大家常说的三层嵌套,如下:  
--三层嵌套,缺一不可
select * from (
       select rownum as rn,b.* from (
              select t.pos_code,t.zh_title  from proposal t where t.pos_code is not null order by t.pos_code)B 
       where rownum<500)C 
where c.rn >=400;

结果
sql 排序分页_第1张图片

1.2 使用分析函数 row_number() over(order by ….) as rn
注:这个函数在sqlserver中的语法也是这样的.

select * from (
       select row_number()over(ORDER BY t.pos_code asc) as rn,t.pos_code,t.psn_code from proposal t)A 
where A.rn >400 and A.rn<=500;

结果
sql 排序分页_第2张图片

你可能感兴趣的:(DB)