SQL中如何把A表的字段数据更新到B表的字段

2024-10-30 23:57:53
推荐回答(5个)
回答1:

首先,你的问题就问的前后矛盾,标题描述是用A表某个字段更新B表的字段,举例子时又说用B表的qiantity更新A表的newqiantity?
假设A表有字段bnum和newqiantity,B表有字段bnum和qiantity,用B表的qiantity值更新对应的A表中的newqiantity值。以Oracle数据库为例:SQL语句如下:
update A set (newqiantity)=(select qiantity from B where A.bnum=B,bnum)

回答2:

你在建表的时候,建立好这2个表之间的关系..我记得有3中选择...就是另外一个表的更新是否影响到和它关连的表.,

回答3:

update
    (select A.bnum ,A.newqiantity,B.qiantity from A left join B on A.bnum=B.bnum) AS C
set C.newqiantity = C.qiantity
where C.bnum =XX

回答4:

update A set newqiantity =
(select qiantity from B where A.bnum = B.bnum)

回答5:

update a set a.newqiantity=b.qiantity FROM A a left join B b on a.bnum=b.bnum