有两个表,A表中有字段,a,b,c,B表中也有a,b,c字段,怎样给A表中的b,c字段赋值成B表中的b,c字段阿?条件是A.a=B.a
我写了update A set 往后就不会了,唉

解决方案 »

  1.   

    create table ta(a int,b int, c int)
    insert ta select 1,1,1 union 
    select 2,2,2 
    create table tb(a int,b int, c int)
    insert tb select 1,3,3 union
    select 2,4,4
    select * from ta
    select * from tbupdate ta set b=tb.b,c=tb.c from ta,tb where ta.a=tb.a
    select * from tadrop table ta,tb
      

  2.   

    update ta set b=tb.b,c=tb.c from ta,tb where ta.a=tb.a
      

  3.   

    楼主讲和不清楚
    若.ta.a对应tb.a有多条.你要求怎么替换.
    如果ta.a  tb.a分别是 ta tb的主键  试下:
    begin transaction
    create table ta(a int,b int,c int)
    insert ta select 1,2,3 union
    select 2,3,4 
    create table tb(a int,b int,c int)
    insert tb select 1,3,3 union all
    select 2,2,2 union all
    select 2,3,2
    select * from ta
    select * from tbupdate ta set b=tb.b,c=tb.c from ta,tb where ta.a=tb.a
    select * from ta
    drop table ta,tbif @@error=0
    commit transaction
    else
    rollback transaction