表A id score
    1   80
    2   60
    3   70
表B id  age
    1   26
    2   24
    3   26
    4   26
要求结果是 更新B表为 id age 
              1   60
              2   80
              3   86
              4   24

解决方案 »

  1.   

    update B 
    set age=case id when 1 then 60 
                    when 2 then 80 
                    when 3 then 86 
                    when 4 then 24
                    else id
            end偶打乱仗
      

  2.   

    根据A表的id关联B表 用score更新age
      

  3.   


    update b set b.age=a.score from B b LEFT JOIN A a ON a.id= b.id
      

  4.   

    找你的说法应该是:
    表A id score 
        1  80 
        2  60 
        3  70 
    表B id  age 
        1  26 
        2  24 
        3  26 
        4  26 id age
    1  80
    2 60
    3 70
    4 26