项目需要,写了个
SQL 分页算法,与网上大部top分页相比,这个算法可以处理第一页:
一、
- --top分页
- --升序
- SELECT * FROM (
- SELECT TOP 10 * FROM tbKuCunJiLuBiao
- WHERE
- (char_KCJLB_SN <=
- (
- SELECT MAX(char_KCJLB_SN) FROM
- (
- SELECT TOP 20 char_KCJLB_SN FROM tbKuCunJiLuBiao
- ORDER BY char_KCJLB_SN ASC
- ) AS T1
- )
- )
- ORDER BY char_KCJLB_SN DESC
- ) as T2
- ORDER BY char_KCJLB_SN ASC
二、
- --top分页
- --倒序
- SELECT * FROM (
- SELECT TOP Page_Size * FROM tbKuCunJiLuBiao
- WHERE
- (char_KCJLB_SN >=
- (
- SELECT MIN(char_KCJLB_SN) FROM
- (
- SELECT TOP (Page_Size * Current_Page) char_KCJLB_SN FROM tbKuCunJiLuBiao
- ORDER BY char_KCJLB_SN desc
- ) AS T1
- )
- )
- ORDER BY char_KCJLB_SN asc
- ) as t2
- ORDER BY char_KCJLB_SN desc
作者:ikmb@163.com