我这里有两张表,一张是A,一张是B 
A的结构如下:
gljg_dm,mc,price,address
B表结构如下:
gljg_dm,address其中A表有10W数据,B表1000数据,要做的是:将B表中的Address更新到A表的Address中,通过gljg_dm关联,这个该如何写呢?

解决方案 »

  1.   

    update tablea a set a.address=(select b.address from tableb where a.gljg_dm=b.gljg_dm and rownum=1)
    where exists(select 1 from tableb c where a.gljg_dm=c.gljg_dm);
      

  2.   

    update tablea a set a.address=(select b.address from tableb b where a.gljg_dm=b.gljg_dm and rownum=1)
    where exists(select 1 from tableb c where a.gljg_dm=c.gljg_dm);
      

  3.   

    我本打算用游标  但是比较麻烦,还有就是a表数据量确实比10w大多了,求sql语句
      

  4.   

    table 是你的表名,C是table的别名
      

  5.   

    使用merge into吧:
    merge into A
    using B
    on(A.gljg_dm=B.gljg_dm)
    when matched then 
    update set A.address=B.address;
      

  6.   

    rownum就是行号,记录你的记录是第几行
      

  7.   

     如果talbea中的字段address和tableb字段中的address一样的话就不需要更新了
    update tablea a set a.address=(select b.address from tableb b where a.gljg_dm=b.gljg_dm and a.address<>b.address and rownum=1)
    where exists(select 1 from tableb c where a.gljg_dm=c.gljg_dm and a.address<>c.address);
      

  8.   

    简单一点写就是这样
    update a set a.address=(select b.address from b where a.gljg_dm=b.gljg_dm and rownum=1)
    where exists(select 1 from b C where a.gljg_dm=C.gljg_dm);