在线等 写条update语句,正确立即结贴 表t1 sno scost 1 15 2 24表t2sno cost1 02 0要求利用t1的scost 修t2的cost,在sno相等的情况下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通用的update t2 set cost=(select scost from t1 where t1.sno=t2.sno)where exists (select 1 from t1 where t1.sno=t2.sno); update t2set t2.cost = ( select t1.scost from t1 where t1.sno = t2.sno)供参考 SQL> select * from t1; SNO SCOST---------- ---------- 1 15 2 24SQL> select * from t2; SNO COST---------- ---------- 1 0 2 0SQL> update t2 set cost=(select scost from t1 where t1.sno=t2.sno) 2 where exists (select 1 from t1 where t1.sno=t2.sno);已更新2行。SQL> commit 2 ;提交完成。SQL> select * from t1; SNO SCOST---------- ---------- 1 15 2 24SQL> select * from t2; SNO COST---------- ---------- 1 15 2 24SQL> update t2 inner join t1 on t2.sno=t1.sno set t2.cost=t1.cost; 救命了: 主键 和 主属性 问题?? sql优化的几种方法 存储过程中比较两个字符串相等!!! 新建oracle实例 这问题还有更简单的解决方法吗? 存储过程中单引号如何用? 如何改变一个表的所有者? ◇◆Oracle中高手看过来~~~~~`一个最最基本的问题!! oracle 存储过程变量传送问题,高手进。 用 in()查询怎么样保证结果的顺序? Oracle 关于取用户生日的问题?很困难啊... 请大家帮忙看看pl/SQL报错提示应该怎样去修改pl/SQL语句,谢谢
where exists (select 1 from t1 where t1.sno=t2.sno);
set t2.cost = (
select t1.scost
from t1
where t1.sno = t2.sno
)
供参考
---------- ----------
1 15
2 24SQL> select * from t2; SNO COST
---------- ----------
1 0
2 0SQL> update t2 set cost=(select scost from t1 where t1.sno=t2.sno)
2 where exists (select 1 from t1 where t1.sno=t2.sno);已更新2行。SQL> commit
2 ;提交完成。SQL> select * from t1; SNO SCOST
---------- ----------
1 15
2 24SQL> select * from t2; SNO COST
---------- ----------
1 15
2 24SQL>