#--放款导出
select ref_id,loan_id,date(loan_paid_at) loan_paid_at,contract_loan_amount loan_amount,funding_code from all_back_0630.loan_manifest
WHERE is_active in (1,-2) AND  loan_paid_at < '2017-01-01';
#还资金方导出- ACD
select ref_id,term_no,funding_code,date(deadline) fund_deadline,date(deadline) fund_repaid_at,principle+interest fund_prin_inst
from audit.funding_repayment_record_acdz where funding_code in (50,80,130);
#还资金方导出- 其他资金方
SELECT t1.ref_id,term_no,t1.funding_code,DATE(deadline) fund_deadline,DATE(repaid_at) fund_repaid_at,principle+interest fund_prin_inst
FROM test_linfang.funding_repayment_record t1
JOIN all_back_0630.`loan_manifest` t2 ON t1.ref_id = t2.ref_id AND t1.`is_active` = 1 AND t1.`funding_code` NOT IN (1,2,3,4,5,210,270,310,320)
AND t2.`loan_paid_at` < '2017-01-01';
#还资金方导出- 渤海广源使用还款计划
select t1.ref_id,term_no ,t1.fund_code funding_code,date(deadline) fund_deadline,date(deadline) fund_repaid_at,principle+interest fund_prin_inst
from all_back_0630.user_repayment_plan t1
join all_back_0630.loan_manifest t2 on t1.ref_id = t2.ref_id and t2.loan_paid_at < '2017-01-01' and
 t1.fund_code in (1,2,3,4,5,210,270,310,320);



