SQL分页

来源:互联网 发布:最好的听书软件 编辑:程序博客网 时间:2024/06/05 19:55
/*sql分页
pagenum 页数
pagerecord 每页记录数*/
--方法一:
select * from (SELECT t.student_code,
       t.name,
       t.sex,
       t.identity,
       row_number() over (order by t.student_code asc) as sortid
  FROM test01 T, test02 T1
 WHERE T.COLLEGE_CODE = T1.COLLEGE_CODE
   and t1.of_province = '62'
   and t.study_start = '20150901'
   )
   where sortid between &pagenum*&pagerecord-(&pagerecord -1)
   and &pagenum*&pagerecord;




--方法二:  
select *
  from (select t.*, rownum
          from (SELECT t.student_code,
                       t.name,
                       t.sex,
                       t.identity,
                       rownum as sortid
                  FROM test01 T, test02 T1
                 WHERE T.COLLEGE_CODE = T1.COLLEGE_CODE
                   and t1.of_province = '62'
                   and t.study_start = '20150901') t)
 where sortid between &pagenum * &pagerecord - (&pagerecord - 1) and
       &pagenum * &pagerecord;
0 0