表T1有一个字段,3条记录:
字段A1
12300
12400
1220表T2有2个字段,4条记录
字段B1     字段B2
12300       1230
12400       1240
12200       1220
12100       1210现在想把T1中的A1字段,通过和T2的连接,全部变成5位数字,得到
A1
12300
12400
12200
该怎么做?
其实涉及的是一个连接问题,但是我看了很多相关的帖子,也套了很久的SQL语句,就是搞不定。
MS-SQL里,这样做很简单:
(UPDATE T1 SET T1.A1=T2.B1 WHERE T1.A1=T2.B2)
oracle里就搞不定了,请大侠帮忙。

解决方案 »

  1.   

    update t1 set a1=(select b2 from t2 where t2.id2=t1.id)
    where exists (select 1 from t2 where t2.id2=t1.id);
      

  2.   

    update T1 set A1=(select B1 from T2 where T2.B2=T1.A1)
    wehre T1.A1 in(select T2.B2 where T2.B2=T1.A1)
      

  3.   

    update T1 set A1 = (select B1 from T2 where T1.A1 = T2.B2)
    where exists (select 1 from T2 where T2.B2 = T1.A1);
      

  4.   

    晕没有附下测试环境和结果的么,还有1楼的兄弟的回复里的ID是啥?
    难道都是GOOGLE到的改了下
      

  5.   

    不好意思 昨天没测试环境
    update T1 set A1=(select B1 from T2 where T2.B2=T1.A1)
    where T1.A1 in(select T2.B2 from T2 where T2.B2=T1.A1)update T1 set A1=(select B1 from T2 where T1.A1=T2.B2)
    where exists (select 1 from T2 where T2.B2 = T1.A1)