Commit 97e512b4 authored by haoyanhui's avatar haoyanhui

还款和逾期sql优化

parent 806c1250
...@@ -360,17 +360,19 @@ ...@@ -360,17 +360,19 @@
end as loanStatus end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus ,if(f.yqze>0,'overdue','normal') termStatus
from ( from (
select a.*,if(c.term_no is null,a.term_no,c.term_no) next_term select -- a.*,
,if(c.deadline is null,a.deadline,c.deadline) next_deadline a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.created_at,
,b.loan_paid_at if(c.term_no is null,a.term_no,c.term_no) next_term
from xyqb_i_repayment_plan a ,if(c.deadline is null,a.deadline,c.deadline) next_deadline
left join xyqb_i_loan_application_manifest_history b ,b.loan_paid_at
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at < #{endTime,jdbcType=VARCHAR} from xyqb_i_repayment_plan a
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id left join xyqb_i_loan_application_manifest_history b
and a.term_no=c.term_no-1 on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at < #{endTime,jdbcType=VARCHAR}
where a.repaid_at>= #{startTime,jdbcType=VARCHAR} and a.repaid_at < #{endTime,jdbcType=VARCHAR} and a.repayment_status=3 left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700) and a.term_no=c.term_no-1
and b.contract_term not in (2,3) where a.repaid_at>= #{startTime,jdbcType=VARCHAR} and a.repaid_at < #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and b.contract_term not in (2,3)
) a ) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
...@@ -467,16 +469,19 @@ ...@@ -467,16 +469,19 @@
when f.yqze=0 and f.dkye>0 then '1' when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus end as loanStatus
,'overdue' termStatus ,'overdue' termStatus
from (select a.* from (
from xyqb_i_repayment_plan a select -- a.*
left join xyqb_i_loan_application_manifest_history b a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.repayment_received_at
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at < #{endTime,jdbcType=VARCHAR} from xyqb_i_repayment_plan a
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and left join xyqb_i_loan_application_manifest_history b
if(b.contract_term>a.term_no,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=0) on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at < #{endTime,jdbcType=VARCHAR}
and floor(DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30 where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700) if(b.contract_term>a.term_no,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and b.transaction_status in (2,5) and floor(DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30
and b.contract_term not in (2,3)) a and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment