根据查询结果更新
merge into … using…
merge into h using m on (h.garage_contract_main_id = m.garage_contract_main_id and h.garage_id = m.garage_id) when matched then update set h.contract_start_date = m.contract_start_date, h.contract_end_date = m.contract_end_date, h.business_start_date = m.business_start_date, h.business_end_date = m.business_end_date, h.file_flag = m.file_flag, h.effective = m.effective where m.contract_start_date is not null and h.contract_start_date is null and m.statu = '1';
解释:
在h表中,找到与m表中具有相同garage_contract_main_id和garage_id的记录,并且只有当m表中的contract_start_date不为空,而h表中的contract_start_date为空,且m表中的statu字段值为’1’时,才更新h表中的contract_start_date、contract_end_date、business_start_date和business_end_date字段