表1 TPADEA料号   最新价格表2 JSKJDB
料号    价格  采购日期
要更新 TPADEA 中的 最新价格 为 JSKJDB中的 最近的 采购日期的那个价格 怎么写  料号为关键字

解决方案 »

  1.   

    update t  set 最新价格=(select top 1 最新价格 from JSKJDB where 料号=t.料号 order by 采购日期  desc) from TPADEA t
      

  2.   

    update TPADEA set 最新价格=价格 from TPADEA A join JSKJDB B on A.料号=B.料号
    where not exists(select 1 from JSKJDB where b.料号=料号 and b.采购日期>采购日期)
      

  3.   

    update tpadea
    set 最新价格=(select top 1 价格 from JSKJDB where 料号=tpadea.料号 order by 采购日期 desc)
      

  4.   


    update 
        t  
    set 
        最新价格=(select top 1 最新价格 from JSKJDB where 料号=t.料号 order by 采购日期  desc) 
    from 
        TPADEA t
      

  5.   

    表1 TPADEA 是不是放少了 日期 字段update a set
      价格 = isnull((select top 1 最新价格 from TPADEA where 料号 = a.料号 and 日期<=a.采购日期  order by 日期 desc),a.价格
    from JSKJDB  a
      

  6.   


    update a  set a.最新价格=b.价格  from tpadea a  join 
     (select * from jskdb a where not exists (select 1 from jskdb where a.料号=料号 and 采购日期>a.采购日期 )) b 
     on a.料号=b.料号
      

  7.   

    update set TPADEA. 最新价格=JSKJDB.价格 from TPADEA,JSKJDB WHERE TPADEA.料号=JSKJDB.料号
      

  8.   


    update TPADEA 
    set 最新价格 =
    (select 1 价格 from JSKJDB where 料号=TPADEA.料号 order by 采购日期  desc)
    from TPADEA