GROUP BY EMP_IDCARD_NO,BUY_STANDARD, INSURANCE_TYPE) cig
ON t.EMP_IDCARD_NO = cig.EMP_IDCARD_NO AND t.POLICY_END = cig.POLICY_END AND t.BUY_STANDARD = cig.BUY_STANDARD and
t.INSURANCE_TYPE = cig.INSURANCE_TYPE
join t_insurance_company tic on t.INSURANCE_COMPANY = tic.ID
join t_insurance_type p on t.INSURANCE_TYPE=p.ID
left join t_insurance_replace tir on t.ID = tir.INSURANCE_ID
LEFT JOIN (select l.* from t_insurance_replace l left join t_business_insurance tbi on l.TO_INSURANCE_ID = tbi.ID where tbi.invalid_Flag='0' and STATUS!=4 ) re ON t.id= re.INSURANCE_ID
select
a.id,
a.EMP_NAME,
a.EMP_IDCARD_NO,
a.DEPT_NAME,
a.DEPT_NO,
a.INSURANCE_COMPANY_NAME,
a.INSURANCE_TYPE_NAME,
a.POLICY_START,
a.POLICY_END,
a.BUY_STANDARD,
a.ACTUAL_PREMIUM,
a.CREATE_NAME,
a.CREATE_TIME,
a.BUY_HANDLE_STATUS,
a.POLICY_NO,
a.MEDICAL_QUOTA,
a.DIE_DISABLE_QUOTA,
a.SETTLE_TYPE,
a.SETTLE_MONTH,
a.INVOICE_NO,
r2.REPLACE_TIME,
a.POLICY_EFFECT,
a.UNIT_NAME,
a.UNIT_NO,
a.REMARK,
a.INSURANCE_PROVINCE_NAME,
a.INSURANCE_CITY_NAME,
a.IS_EFFECT,
a.POST,
r.fromEmpName,
r.toEmpName,
r.REPLACE_TIME as "toReplaceTime",
a.IS_OVERDUE,
a.ESTIMATE_PREMIUM,
rf.REFUND_MONEY,
rf.CREATE_TIME as "refundCreateTime",
rf.CREATE_NAME as "refundCreateUser",
a.CREATE_USER_DEPT_NAME
from t_insurance_detail a
LEFT JOIN view_insurance_replace r on a.id=r.TO_INSURANCE_DETAIL_ID
LEFT JOIN view_insurance_replace r2 on a.id=r2.FROM_INSURANCE_DETAIL_ID
LEFT JOIN t_insurance_refund rf on rf.INS_DETAIL_ID=a.id