各位好,碰到一个问题,特向各位请教 
有一个学生补助发放表 a , 有 以下结构
id,xm,price
1,1,10
2,2,10
1,1,20
我现在想把 相同的人所发的资金汇总合并,并能表示出这个表所有数据,我要得到结果如
id,xm,price
1,1,30
2,2,10
请教大虾我该怎么处理。谢谢。在线等待。

解决方案 »

  1.   

    select [id],[xm],sum([price]) as price from tb group by [id],[xm]
      

  2.   

    declare @a table([id] int,[xm] int,[price] int)
    Insert @a
    select 1,1,10 union all
    select 2,2,10 union all
    select 1,1,20
    select [id],[xm],sum([price]) as price from @a group by [id],[xm]
    /*
    id          xm          price
    ----------- ----------- -----------
    1           1           30
    2           2           10*/
      

  3.   

    select id,xm,sum(price)
    from a
    group by id,xm
      

  4.   

    create   table Table_A (id int,xm varchar(10),price int)
    Insert Table_A
    select 1,'1',10 union all
    select 2,'2',10 union all
    select 1,'1',20select id,xm,sum(price) as price 
      from Table_A group by id,xm
      

  5.   

    非常感谢各位大虾 的帮助,现在问题已经解决了。但现在有另外一个问题,又有一个扣款表,要完成这样一个功能:奖金表与扣款表相减,但不是全部的学生相减,而是部分,如
    id,xm,xh,bm,pri
    2,2,2009,计算机院,5
    则相减后得到
    id,xm,price
    1,1,30
    2,2,5
    是否可以这样实现
    update a set price=price-pri from a,b where a.id=b.id
      

  6.   

    update a set a.price=a.price-b.pri from a inner join b on a.id=b.id and a.xm = b.xm