这个update怎么写啊?

aaajj 2008-11-19 03:24:17

create table aa(a number, b number, c number)
create table bb(a number, b number, c number)

aa
a b c
1 0 0
2 0 0
3 0 0


bb
a b c
1 1 1
2 2 2
3 3 3
4 4 4
现在要根据aa中的a字段和bb中的a字段来更新aa的数据,得到
a b c
1 1 1
2 2 2
3 3 3

我想到了这种方法,但是不好,重复了
update aa ta set ta.b = (select b from bb where ta.a = a),ta.c = (select c from bb where ta.a = a)

大家帮忙看看
...全文
196 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
martin_maxm 2008-11-19
  • 打赏
  • 举报
回复
oracle和sql server的语法都不一样啊,郁闷。sqlserver里这样的可以。oracle不熟悉


update aa
set
aa.b = bb.b,
aa.c = bb.c
from bb
where aa.a = bb.a
Andy__Huang 2008-11-19
  • 打赏
  • 举报
回复
路过!
xcluii 2008-11-19
  • 打赏
  • 举报
回复

update
select aa.b b1, aa.c c1, bb.b b2, bb.c c2
from aa, bb
where aa.a = bb.a
set
(
b1 = b2,
c1 = c2
)
;
sleepzzzzz 2008-11-19
  • 打赏
  • 举报
回复
让得加上where exists...,不然你这种数据的更新会有问题,自己试一下就知道.
sleepzzzzz 2008-11-19
  • 打赏
  • 举报
回复
update aa ta
set (ta.b, ta.c) = (select b, c from bb where ta.a = a)
where exists (select 1 from bb where ta.a = a);
yf520gn 2008-11-19
  • 打赏
  • 举报
回复

update aa
set (a,b,c)
=(select a,b,c from bb where bb.a=aa.a)
where exists (select a,b,c from bb where bb.a=aa.a)
wfqqwer5213 2008-11-19
  • 打赏
  • 举报
回复
update aa ta set (ta.b,ta.c) = (select b,c from bb where ta.a = a);
zhgrm 2008-11-19
  • 打赏
  • 举报
回复
路过看看

17,382

社区成员

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

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