现在的位置: 首页 > 综合 > 正文

postgresql 常用分页计算

2013年10月08日 ⁄ 综合 ⁄ 共 512字 ⁄ 字号 评论关闭

1. 输入参数

nPageSize  每页包含的记录数量

nPageIndex   要显示的页码,>=1

strOrderByFieldName  排序字段

strOrderByDirection  排序方向

other  其他查询条件

 

2. 计算总页数

nTotalCount  总的记录数,从 select count(*) from xxx where other 取得值

nPageCount  总的页数

 

nPageCount = (nTotalCount-1)/nPageSize+1

 

3. 计算记录的开始索引(不包含)

nRecordIndex  记录的开始索引(不包含)

 

nRecordIndex = nPageSize*(nPageIndex-1)

 

4. 获取最后结果

select count(*) from xxx

where other

ORDER BY [#strOrderByFieldName]  [#strOrderDirection]

LIMIT [#nPageSize] OFFSET [#nRecordIndex]

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guo_rui22/archive/2009/07/05/4323277.aspx

抱歉!评论已关闭.