日期:2014-05-18  浏览次数:20463 次

求从一个表更新数据到另一个表中的sql?
T1表:
cust   model   price
a         b           11
a         e           22

T2表:
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

------解决方案--------------------
--笔误
--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