select a.id, a.name, a.type, a.code, a.bank_card_lend_id, a.installment_amount, a.installment_date, a.period, ( select CASE WHEN sum(ihd.current_amount) is null THEN 0 ELSE sum(ihd.current_amount) END from installment_history_detail ihd where ihd.installment_history_id = a.id and ihd .posting_state = '0' ) as balance, ( select min(d.repayment_date) from installment_history_detail d where d.installment_history_id = a.id and d.posting_state = '0') as repayment_date, a.repaid_period, a.total_interest, a.interest_rate, a.due_date, a.close_date, a.state, a.create_by, a.create_time, a.update_by, a.update_time, a.del_flag, a.remark, bc."name" as bank_name, bc.code as bank_code from installment_history a left join bank_card_lend bc on bc.id = a.bank_card_lend_id insert into installment_history id, name, type, code, bank_card_lend_id, installment_amount, installment_date, period, repaid_period, total_interest, interest_rate, due_date, close_date, state, create_by, create_time, update_by, update_time, del_flag, remark, balance, #{id}, #{name}, #{type}, #{code}, #{bankCardLendId}, #{installmentAmount}, #{installmentDate}, #{period}, #{repaidPeriod}, #{totalInterest}, #{interestRate}, #{dueDate}, #{closeDate}, #{state}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{delFlag}, #{remark}, #{balance}, update installment_history name = #{name}, type = #{type}, code = #{code}, bank_card_lend_id = #{bankCardLendId}, installment_amount = #{installmentAmount}, installment_date = #{installmentDate}, period = #{period}, repaid_period = #{repaidPeriod}, total_interest = #{totalInterest}, interest_rate = #{interestRate}, due_date = #{dueDate}, close_date = #{closeDate}, state = #{state}, create_by = #{createBy}, create_time = #{createTime}, update_by = #{updateBy}, update_time = #{updateTime}, del_flag = #{delFlag}, remark = #{remark}, balance = #{balance}, where id = #{id} delete from installment_history where id = #{id} delete from installment_history where id in #{id} update installment_history set del_flag='1' where id = #{id} update installment_history set del_flag='1' where id in #{id}