在线等 写条update语句,正确立即结贴

xiaohu8855 2010-02-05 10:41:57
表t1
sno scost
1 15
2 24
表t2
sno cost
1 0
2 0

要求利用t1的scost 修t2的cost,在sno相等的情况下
...全文
50 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
leonbanana 2010-02-05
  • 打赏
  • 举报
回复
update t2 inner join t1 on t2.sno=t1.sno set t2.cost=t1.cost;
xiaohu8855 2010-02-05
  • 打赏
  • 举报
回复
谢了啊
YY_MM_DD 2010-02-05
  • 打赏
  • 举报
回复
楼主都看那么一点点就好了
suiziguo 2010-02-05
  • 打赏
  • 举报
回复
SQL> select * from t1;

SNO SCOST
---------- ----------
1 15
2 24

SQL> select * from t2;

SNO COST
---------- ----------
1 0
2 0

SQL> 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 24

SQL> select * from t2;

SNO COST
---------- ----------
1 15
2 24

SQL>



vanjayhsu 2010-02-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 suiziguo 的回复:]
通用的

update t2 set cost=(select scost from t1 where t1.sno=t2.sno)
where exists (select 1 from t1 where t1.sno=t2.sno);
[/Quote]

好快啊。。。
yaoweijq 2010-02-05
  • 打赏
  • 举报
回复
update t2
set t2.cost = (
select t1.scost
from t1
where t1.sno = t2.sno
)
供参考
suiziguo 2010-02-05
  • 打赏
  • 举报
回复
通用的

update t2 set cost=(select scost from t1 where t1.sno=t2.sno)
where exists (select 1 from t1 where t1.sno=t2.sno);

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧