两个表 test1和test2
test1四个字段a,b,c,d
test2两个字段a,b
怎么把test2的值加到test1里  
就是test2的a加到test1的字段a里,b加到字段b里
谢谢

解决方案 »

  1.   

    insert into test1 select a,b from test2;
      

  2.   


    Update test1 t1
    Set (t1.a,t1.b)=(select t1.a+t2.a,t1.b+t2.b from test2 t2
                      where t1.a=t2.a and t1.b=t2.b )
    where  exists(select 1 from test2 t2
                      where t1.a=t2.a and t1.b=t2.b)
      

  3.   

    insert into test1(a,b) select a,b from test2;
      

  4.   


    insert into test2(a,b) select a.a,a.b from test1 a where not exists(select 1 from test2 b where a.a=b.a and a.b=b.b)merge into test2 a using test1 b on(a.a=b.a and a.b=b.b)
    when not matched then
    insert(a.a,a.b) values(b.a,b.b)
      

  5.   


    insert into test1 select a,b from test2;无其他条件限制的话,这样就OK了…
      

  6.   

    楼上有正解了!insert into test2(a,b) select a,b from test1
      

  7.   


    上面是有不插入重复的  没有的话
    insert into test2(a,b) select a,b from test1