有表t1(订单号,金额,流水号,创建时间,状态……)
表t2(订单号,金额,流水号,创建时间,状态……)
要把 t1 表的数据 全部插入到t2 ,但是如果 订单号、金额、流水号 ’同时相等‘ ,此条跳过
要怎么完成???
sql语句 存储过程都行
------解决方案--------------------
- SQL code
insert into t2 select * from t1 not exists (select 1 from t2)
------解决方案--------------------
- SQL code
insert t2 select * from t1 except select * from t2 --该种写法 两表字段数量必须相等(如果有自增ID ,最好将具体的列 列出)--或者insert t2 select * from t1 not exists ( select * from t2 where t2.订单号=t1.订单号 and t2.金额=t1.金额 and t2.流水号=t1.流水号)
------解决方案--------------------
excepte这个关键字你到联机丛书查查能不能用。not exists的效率没这个好。具体用法忘了