update A set a.money1=(select b.money2 from b where a.id=b.id); 本身是没有什么问题的. 除非money2中同一个ID对应了几个money2的自段. update a set a.money1=(select money2 from (select id,sum(money2) money2 from b group by id) b where a.id=b.id) 应该可以了.
update A set money1=b.money2 from B where B.id=A.id
update A set money1=(select money2 from B where A.id=B.id) where id in (select id from B)这样应该就不会有我上面说的问题了,呵呵
update A set a.money1=(select b.money2 from b where a.id=b.id); 分析: 1:如果A表中有数据,但是在B表中没有a.id=b.id的数据,那么,该条数据将被置为空。 2:就是所讲的多值问题。就是满足a.id=b.id的数据有多条。 可以修改为: update A set a.money1=(select max(b.money2) from b where a.id=b.id) where exists (select * from c where a.id=c.id);
本身是没有什么问题的.
除非money2中同一个ID对应了几个money2的自段.
update a set a.money1=(select money2 from
(select id,sum(money2) money2 from b group by id) b
where a.id=b.id)
应该可以了.
分析:
1:如果A表中有数据,但是在B表中没有a.id=b.id的数据,那么,该条数据将被置为空。
2:就是所讲的多值问题。就是满足a.id=b.id的数据有多条。
可以修改为:
update A set a.money1=(select max(b.money2) from b where a.id=b.id) where exists (select * from c where a.id=c.id);