用个临时表,或在你的原表中增加一个辅助字段就能实现下面用临时表的方法来实现:--生成带辅助字段的临时表 select M,N,cast(0 as bigint) as aa into #tb from 你的表 --处理表数据 declare @a bigint,@m int set @a=0 update #tb set @a=case @m when m then @a else @a+1 end ,aa=@a,@m=m --显示结果 select M,N from (select min(M) as M,sum(N) as N,aa from @tb group by aa) a--删除临时表 drop table #tb
下面是我做的测试,我是在原表上加了一个辅助处理字段aa--创建数据测试环境 declare @tb table(M int,N int,aa int) insert into @tb(M,N) select 1,4 union all select 2,6 union all select 3,7 union all select 4,2 union all select 4,7 union all select 5,8 union all select 6,9 union all select 4,2 union all select 7,5 union all select 7,3--处理数据 declare @a bigint,@m int set @a=0 update @tb set @a=case @m when m then @a else @a+1 end ,aa=@a,@m=m--得到结果 select M,N from (select min(M) as M,sum(N) as N,aa from @tb group by aa) a
select M,N,cast(0 as bigint) as aa into #tb from 你的表
--处理表数据
declare @a bigint,@m int
set @a=0
update #tb set @a=case @m when m then @a else @a+1 end
,aa=@a,@m=m
--显示结果
select M,N from
(select min(M) as M,sum(N) as N,aa from @tb group by aa) a--删除临时表
drop table #tb
declare @tb table(M int,N int,aa int)
insert into @tb(M,N)
select 1,4
union all select 2,6
union all select 3,7
union all select 4,2
union all select 4,7
union all select 5,8
union all select 6,9
union all select 4,2
union all select 7,5
union all select 7,3--处理数据
declare @a bigint,@m int
set @a=0
update @tb set @a=case @m when m then @a else @a+1 end
,aa=@a,@m=m--得到结果
select M,N from
(select min(M) as M,sum(N) as N,aa from @tb group by aa) a
这里有老龟奴zyq_123雍亲正当大版主,还有人称辣花摧魔前青楼名妓smoke当镇小版主,肯定能满足您的需要!!!快来吧~~~~~~