请看看下面的例子:
M  N
1  4
2  6
3  7
4  2
4  7
5  8
有2个4相同,则合并2+7=9,其值保存到另一表即可。
合并后列表为:
M  N
1  4
2  6
3  7
4  9
5  8
要怎样实现?

解决方案 »

  1.   

    Select M,sum(N) from yourTable group by M
      

  2.   

    Select M,sum(N) 和 from 你的表 group by M
      

  3.   

    用个临时表,或在你的原表中增加一个辅助字段就能实现下面用临时表的方法来实现:--生成带辅助字段的临时表
    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
      

  4.   

    下面是我做的测试,我是在原表上加了一个辅助处理字段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
      

  5.   

    想找小姐吗,来水园吧!
    这里有老龟奴zyq_123雍亲正当大版主,还有人称辣花摧魔前青楼名妓smoke当镇小版主,肯定能满足您的需要!!!快来吧~~~~~~