以XT_GG_CZY 表为例
1、 查询出表中的记录数目
SELECT COUNT(0)
FROM XT_GG_CZY
2、 利用ROW_NUMBER() OVER() 对结果进行数字排序,
select row_number() over() as NUM,A.ID, A.YYBH, A.BM, A.XM, A.KL, A.KS, A.XB, A.ZW, A.ZC, A.JS, A.KSSJB, A.PTZCH, A.SHENFEN, A.PYM, A.BQBM
from xt_gg_czy A
3、根据需要查询的是第几页,写出查询SQL
SELECT B.*
FROM
(select row_number() over() as NUM,A.ID, A.YYBH, A.BM, A.XM, A.KL, A.KS, A.XB, A.ZW, A.ZC, A.JS, A.KSSJB, A.PTZCH, A.SHENFEN, A.PYM, A.BQBM
from xt_gg_czy A
) B
WHERE B.NUM>=1
AND B.NUM<=10
AND B.NUM<
(SELECT COUNT(0)-10
FROM XT_GG_CZY)
红色为根据要查询的页数算出这一页的第一条记录和最后一条记录在总的查询结果中的NUM