日期:2014-05-17  浏览次数:20443 次

菜鸟求帮助 在线等··怎样把一个表里面的数据加到另一个表
table1 id,summoney table2 id, money,kind
  table1为空表,
  table2 1,10,a
  2,21,b
  3,15,c
  。。。。。。。。。。。。
  1,20,b
  2,20,a

  。。。。。。。。。。。。
  现在怎样将table2里面kind为a和b的money相加的和存入到table1的summoney里面
  table1和table2里面的id对应,在table1里面id不重复,并且table1里面只存储kind为a和b或a,b的和的字段
 

------解决方案--------------------
ins
SQL code
ert into table1 (id,summoney) select id ,sum(money) from table2 group by id

------解决方案--------------------
insert into table1(id,summoney)
select id,sum(money)
from table2
group by id
------解决方案--------------------
怎么个相加办法 看的不是很懂啊


猜一个
SQL code
insert into table1 
select id,sum(money) from table2  where kind in('a','b')
group by id

------解决方案--------------------
SQL code
insert into table1 (id,summoney) select id ,sum(money) from table2 group by id

------解决方案--------------------
如果你的table1有数据,那要用update,如果没数据,就用insert
我给个insert 的例子

insert into table1
select a.id,b.money+b.kind
from table1 a inner join table2 b on a.id=b.id
------解决方案--------------------
探讨

引用:
如果你的table1有数据,那要用update,如果没数据,就用insert
我给个insert 的例子

insert into table1
select a.id,b.money+b.kind
from table1 a inner join table2 b on a.id=b.id

b.money+b.kind 什么意思?
我要的……