merge into OD041_TEMP b using a on(b.a= a.a and b.b = a.b ...) when not matched then insert (b.a,b.b) values(a.a,a.b)
要插入的数据为 月金额MP 合同编号为C_ID insert into B(月金额,合同编号) select 月金额,合同编号 from A where A.月金额=MP and A.合同编号= C_ID;
insert into finance_temp1(amount,contract_id) select a.amount,a.contract_id from finance_temp a,finance_temp1 b where a.amount=b.amount and a.contract_id=b.contract_idfinance_temp1为你说的b,finance_temp为你所谓的a.楼主的需求说的有些绕,以上语句实现的是:b表中的两个字段的数据,判断在a表中存在的时候,插入b表(要插入其他字段的话楼主自己修改)
insert into B(monthMoney,sid,column1,column2,.....)values(mm1,sidValue,columnValue1,columnValue2,......) where exists(select 1 from A where A.monthMoney=mm1 and A.sid=sidValue)其中mm1,sidValue为insert的值。
--merge into合适 merge into b using a on(a.合同编号=b.合同编号 and a.月金额=b.月金额) when not matched then insert(b.合同编号,b.月金额) value(a.合同编号,a.月金额)
using a
on(b.a= a.a and b.b = a.b ...)
when not matched then
insert (b.a,b.b)
values(a.a,a.b)
insert into B(月金额,合同编号)
select 月金额,合同编号
from A
where A.月金额=MP and A.合同编号= C_ID;
select a.amount,a.contract_id from finance_temp a,finance_temp1 b
where a.amount=b.amount and a.contract_id=b.contract_idfinance_temp1为你说的b,finance_temp为你所谓的a.楼主的需求说的有些绕,以上语句实现的是:b表中的两个字段的数据,判断在a表中存在的时候,插入b表(要插入其他字段的话楼主自己修改)
insert into B(monthMoney,sid,column1,column2,.....)values(mm1,sidValue,columnValue1,columnValue2,......)
where exists(select 1 from A where A.monthMoney=mm1 and A.sid=sidValue)其中mm1,sidValue为insert的值。
merge into b using a on(a.合同编号=b.合同编号 and a.月金额=b.月金额)
when not matched then
insert(b.合同编号,b.月金额) value(a.合同编号,a.月金额)