select a.id,
a.pay_id,
a.bill_no,
a.pay_money,
a.del_flag,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.create_site,
a.update_site,
(
select r.apply_seq_no
from emis_settle_invoice_rel r
where r.bill_no = a.bill_no
and r.del_flag = '0'
and exists (
select 1 from emis_settle_pay_invoice_rel p
where p.apply_seq_no = r.apply_seq_no
and p.pay_id = a.pay_id
and p.del_flag = '0'
)
limit 1
) as apply_seq_no
from emis_settle_pay_rel a
insert into emis_settle_pay_rel
id,pay_id,bill_no,pay_money,del_flag,create_by,create_time,update_by,update_time,create_site,update_site,#{id},#{payId},#{billNo},#{payMoney},#{delFlag},#{createBy},#{createTime},#{updateBy},#{updateTime},#{createSite},#{updateSite},
update emis_settle_pay_rel
pay_id = #{payId},bill_no = #{billNo},pay_money = #{payMoney},del_flag = #{delFlag},create_by = #{createBy},create_time = #{createTime},update_by = #{updateBy},update_time = #{updateTime},create_site = #{createSite},update_site = #{updateSite},
where id = #{id}
update emis_settle_pay_rel set del_flag='1' where id = #{id}
update emis_settle_pay_rel set del_flag='1' where id in
#{id}