日期:2014-05-17  浏览次数:20746 次

请教更快的方法!在线等高人解答
表1
      id     money
        1         2.5
        ........  
表2
      id1   money1
        1         3
          .......
用表2去修改表1的内容,我写的是:
update   表1   set   money=(select   a.money1   from   表2   a   where   a.id1=id)  
where     id   in   (select   id1   from   表2)
一共30万条,执行很慢,请教更好的方法.马上给分,谢谢

------解决方案--------------------
update 表1 set a.money=b.money1 from 表1 a,表2 b where a.id=b.id1
------解决方案--------------------
update 表1 b set money=(select a.money1 from 表2 a where a.id1=b.id)
------解决方案--------------------
不好意思,错了
------解决方案--------------------
update 表1 b set money=nvl((select a.money1 from 表2 a where a.id1=b.id),b.money)

会不会快点呢?

------解决方案--------------------
create table 表3
as
select a.id,b.money1 from 表1 a,表2 b
where a.id=b.id1;

update 表1 set money=(select a.money1 from 表3 a where a.id1=id)

建个临时表,不知道会不会快点!
------解决方案--------------------
这个应该是可行的:
update 表1 b set money=(select a.money1 from 表2 a where a.id1=b.id)
如果还不行,应该在id1、id 上建立索引。

------解决方案--------------------
update 表1 a set a.money=(select b.money1 from 表2 b where a.id=b.id1)