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