有2张数据表
第一张表new
item_no     sale_price
6901         22.00
6902         11.00
8802         12.90
9902         33.33第二张表old
item_no     sale_price
6901         33.40
7702         55.20
9902         31.00
8802         12.90
更新条件
前提item_no相同的条件下用OLD表中的sale_price替换NEW表中sale_price的数据
update new
set new.sale_price = old.sale_price
from new,old
where new.item_no = old.item_no

解决方案 »

  1.   

    update new set sale_price=(select sale_price from old where item_no=new.item_no)
      

  2.   

    就用lz自己的吧
    update new 
    set sale_price = old.sale_price 
    from new,old 
    where new.item_no = old.item_no 
    --用此似乎效率更低
    update new
    set sale_price=(select top 1 from old where item_no=new.item_no)
    where exists(select * from from old where item_no=new.item_no)