博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql多表连接,分组例子
阅读量:6993 次
发布时间:2019-06-27

本文共 627 字,大约阅读时间需要 2 分钟。

hot3.png

多表查询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"

转载于:https://my.oschina.net/yukong/blog/904567

你可能感兴趣的文章