网上介绍关于数据库分页有很多方法,现在我主要是采用临时表进行分页。
1,数据先存放到临时表中。
select identity(int,1,1) as rownum ,列1,列2 into temp from 表 where 条件 order by 列1;
例:
select identity(int,1,1) as rownum ,orgname into temp from assetinfo a
inner join organization t on a.orgid = t.orgid
left outer join department d on a.deptid = d.deptid
where a.name='XX' order by t.orgname asc;
注意:identity(int,1,1) as rownum 表示在新表中增加一列自动增长的列。
2,查询临时表数据
select * from temp where rownum>={0} and rownum<{1};
第一个参数:
currentPage * rowsPerPage + 1 - rowsPerPage
当前页*当前行数+1-每页显示行数。
第二个参数:
currentPage * rowsPerPage + 1
当前页*每页显法行数+1
3,最后删除临时表
drop table temp;
以上只是针对SQL 数据库分页的一种方法。