如何计算出分组记录所在的页码[sql2000]!
记录按组号及创建时间排序,要求计算出每条记录所在的页码,
计算方法,每组记录条数不定,每一组额外加一行汇总行并放在最后
,每3条分一页,记录组id变化时,需要换页,页码加1(即一页内只有一个组,最多3条记录,也可以少)
[sql server 2000 中实现 ]
示例数据如下,以3条分一页,实际可能会是20或30
create table t( groupid int,cdt datetime,pageno int)
insert into t(groupid,cdt)
select 1,'2012-01-01'
union all
select 1,'2012-01-02'
union all
select 1,'2012-01-03'
union all
select 1,'2012-01-04'
union all
select 1,'2012-01-06'
union all
select 1,'2012-01-11'
union all
select 2,'2012-01-12'
union all
select 2,'2012-01-22'
union all
select 2,'2012-01-23'
union all
select 3,'2012-01-25'
产生的结果
1,'2012-01-01' 页码:1
1,'2012-01-02' 页码:1
1,'2012-01-03' 页码:1
1,'2012-01-04' 页码:2
1,'2012-01-06' 页码:2
1,'2012-01-11' 页码:2
--此处groupid=1的额外加一行汇总行占用页码3
2,'2012-01-12' 页码:4
2,'2012-01-22' 页码:4
2,'2012-01-23' 页码:4
--此处groupid=2的额外加一行汇总行占用页码5
3,'2012-01-25' 页码:6
将页码中的数字更新到pageno字段中.
select * from t 查询结果
1,'2012-01-01' 1
1,'2012-01-02' 1
1,'2012-01-03' 1
1,'2012-01-04' 2
1,'2012-01-06' 2
1,'2012-01-11' 2
2,'2012-01-12' 4
2,'2012-01-22' 4
2,'2012-01-23' 4
3,'2012-01-25' 6
------解决方案--------------------------------------------------------
楼上正解
------解决方案--------------------------------------------------------
学习中,呵呵,,,