当前位置: 代码迷 >> Oracle管理 >> 大家帮帮忙,oracle中 两个表关联 update的有关问题
  详细解决方案

大家帮帮忙,oracle中 两个表关联 update的有关问题

热度:34   发布时间:2016-04-24 05:57:51.0
大家帮帮忙,oracle中 两个表关联 update的问题
例子:
  a表 字段 id price
  b表 字段 id num
 
我想 把a表中的price update为 a.price*b.num where a.id=b.id
 这个sql语句怎么写?
以前在sql server中写过,但在oracle中 有问题?

------解决方案--------------------
update a
set a.price = (select a.price*b.num from b where a.id = b.id);

试试看~~
------解决方案--------------------
update a 
set a.price = (select a.price*b.num from b where a.id = b.id)
where exists 
(select '1' from b where a.id=b.id); 

------解决方案--------------------
如果B表中id字段是主键,那么还可以写为
update (select a.id,a.price,b.num from a,b where a.id=b.id) set price=price*num
  相关解决方案