表t1 
sno  scost 
1      15 
2      24
表t2
sno  cost
1     0
2     0要求利用t1的scost 修t2的cost,在sno相等的情况下

解决方案 »

  1.   

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

  2.   

    update t2
    set t2.cost = (
        select t1.scost 
        from   t1
        where  t1.sno = t2.sno
    )
    供参考
      

  3.   

    SQL> select * from t1;       SNO      SCOST
    ---------- ----------
             1         15
             2         24SQL> select * from t2;       SNO       COST
    ---------- ----------
             1          0
             2          0SQL> 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         24SQL> select * from t2;       SNO       COST
    ---------- ----------
             1         15
             2         24SQL>
      

  4.   

    update t2 inner join t1 on t2.sno=t1.sno set t2.cost=t1.cost;