如何通过 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
比如
A:
xh cj1
001
002
003B:
xh cj
001 100
002 200
003 300结果:
A:
xh cj1
001 100
002 200
003 300
where exists (select 1 from b where a.xh=b.xh)
where exists (select 1 from B where a.xh=b.xh)
--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)
where exists (select * from B where a.xh=b.xh);