2个表:b1 和  b2
b1中字段:  a1,a2,a3
c2中字段:  b1,b2,a3
现在想用c2中的b2替换b1中a2,条件是b1中的a1=‘111’ ,c2中的b1=‘222’(带条件的两个表内内容一样只是用其中一个表的一个字段内容替换另一个表中的字段内容)
a3是两个表的共有字段,可相等,不唯一

解决方案 »

  1.   

    B1表
    a1   a2   a3
    111   2    0
    111   3    0
    111   4    1B2表
    b1  b2  b3
    222  50  0
    222  60  0
    222  70  0
    222  80  2怎么替换?替换条件呢?不懂?
      

  2.   

    update b1 set b1.a2=c2.b2 from c2 left join b1 on (b1.a3=c2.a3) where b1.a1='111' and c2.b1='222'
      

  3.   

    如果表c2中b1是唯一的
    update b1 set a2=(select b2 from c2 where b1='222') where a1='111'
      

  4.   

    update a set a.a2=b.b2 
    from b1 a 
    left join b2 b on a.a3=b.a3 
    where a.a1='111' and b.b1='222'
      

  5.   

    update b1 set b1.a2=c2.b2 
    from c2,b1 
    where b1.a3=c2.a3 and b1.a1='111' and c2.b1='222'