如何通过 SQL语句,将A(xh,cj1)表的cj1列的值,更新为B(xh,cj)的cj值。
比如
A:
xh cj1
001
002
003B:
xh cj
001 100
002 200
003 300结果:
A:
xh cj1
001 100
002 200
003 300

解决方案 »

  1.   

    update A set c1=(select c2 from B where A.xh=b.xh)
    where  exists (select 1 from b where a.xh=b.xh) 
      

  2.   

     update A set cj=(select cj1 from B where A.xh=B.xh)
    where exists (select 1 from B where a.xh=b.xh)
     
      

  3.   


    --merge
    merge into a using b on(a.xh=b.xh)
    when matched then update set a.cj1=b.cj
    update a set a.cj1=(select cj from b where a.xh=b.xh)
      

  4.   

    update A set cj1=(select cj from B where A.xh=B.xh)
    where exists (select * from B where a.xh=b.xh);