读书人

update用法解决办法

发布时间: 2012-02-28 13:06:35 作者: rapoo

update用法
如何将a表中的b字段赋值给c表的d字段 c.d=a.b,求解

详细说明:
我要更新很多条 我要将a中的b字段和c表中的d字段
table a table c
b x d x
1 1
2 2
3 3
update c set d=(select b from a where ?) where x in()
我要分别把c表中x=1,2,3对应的d的值赋给a表中x=1,2,3对应的b值
单条更新的我已会写,感谢1楼的回复。
请高手指点 关联性如何写?

[解决办法]

SQL code
update c set d = (    select b from a where a.x = c.x)where exists  (    select b from a where a.x = c.x)
[解决办法]
SQL code
update a set a.字段=(                     select b.字段 from b                    where a.key=b.key) where a.key in (select c.key  from c where a.key=c.key)        b与c为同一个表 

读书人网 >IBM DB2

热点推荐