多表查询union all 作为子表,为分组聚合查询使
select udata.loan_id, MAX(udata.creation_time) as max_time from ( "
+ "(select loan_id as loan_id, creation_time from auto_collection_call as acc where loan_id in (:loanIds) and success=true) " + "union all " + "(select loan_id, creation_time from debt_collection_remark where loan_id in (:loanIds)) and contact_failed_reason IS NULL and dtype=PHONE_COLLECTION_REMARK) " + "union all " + "(select loan_id, detail_Time from auto_detection_call where loan_id in (:loanIds) and success = :success) " + ")as udata " + "group by udata.loan_id order by max_t"