表1 A
Aa    Ab     Ac      Ad
101  1    
101  2
102  1
102  2表2 B
Ba    Bb    Bc     Bd
101   1     001    10
101   1     002    20
102   1     001    10
102   1     002    20
101   2     001    10
102   2     002    20更新为
表1 A
Aa     Ab      Ac(001)    Ad(002)
101    1       10         20
102    1       10         20
101    2       10
102    2                  20不知道清不清楚

解决方案 »

  1.   

    update A set 
    Ac=(select top 1 bd from B where bc='001' and ba=Aa and Bb=Ab),
    Ad=(select top 1 bd from B where bc='002' and ba=Aa and Bb=Ab)
      

  2.   

    Update table1 set AC=(case when Bc='001' then Bd  else 0 end)
    ,Ad=(case when Bc='002' then Bd  else 0 end) from table1,table2 where Aa=Ba And Ab=Bb
      

  3.   

    update a set ac=(select sum(Bd) from b where Ba=a.Ba and Bb=a.Bb and Bc='001')
    ,ad=(select sum(Bd) from b where Ba=a.Ba and Bb=a.Bb and Bc='002')
      

  4.   

    update a set ac=(select sum(Bd) from b where Ba=a.Aa and Bb=a.Ab and Bc='001')
    ,ad=(select sum(Bd) from b where Ba=a.Aa and Bb=a.Ab and Bc='002')
      

  5.   

    update a set ac=(select sum(Bd) from b where Ba=a.Ba and Bb=a.Bb and Bc='001')
    ,ad=(select sum(Bd) from b where Ba=a.Ba and Bb=a.Bb and Bc='002')