update table2
set [money]=table2.[money]+table1.[money]
from table1
where table2.name=table1.nameinsert table2(name,[money])
select name,[money] from table1
where not exists (
select 1 from table2
where table2.name=table1.name
)

解决方案 »

  1.   

    update table2 set money=L.money+R.money from table2 L join table1 R on L.name=R.name
      

  2.   

    上面是修改table2的方法
    如果不需要修改table2,而是只要select加总的结果select name,sum([money]) as [money]
    from (
    select * from table1
    union all
    select * from table2
    ) as x
    group by name
      

  3.   

    还忘了一句update table2 set money=L.money+R.money from table2 L join table1 R on L.name=R.name
     
    insert  table2 select * from table1 where name not in(select name from table2)