T1表:
cust model price
a    b     11
a    e     22T2表:
cust model price
a    b     1
a    c     2从T1表中导入数据到T2表中,如果T2表中没有T1表中的cust与model则insert,
有则update该cust与model对应的price.这样的sql怎么写比较好?
执行后得到这样的结果:
cust model price
a    b      11
a    c      2
a    e      22

解决方案 »

  1.   

    update T2 set T2.price=T1.price from T2,T1 where T1.cust=T2.cust and T1.model=T2=modelinsert T2 select * from T1 a where not exists (select 1 from T2 where cust=a.cust and model=a.model)
      

  2.   

    insert into t2  select * from t1 a where cust<>a.cust or model<>a.model
    update t2 set price=a.price from t1 a where cust=a.cust and model=a.model
      

  3.   

    --笔误
    --update T2 set T2.price=T1.price from T2,T1 where T1.cust=T2.cust and T1.model=T2=model
    update T2 set T2.price=T1.price from T2,T1 where T1.cust=T2.cust and T1.model=T2.model