SELECT * FROM `pay_detail` WHERE is_ptf = 0 AND loan_time >= '2017-01-01'
AND loan_time < '2017-02-01' AND product_no NOT IN (
SELECT product_no FROM `repayment_plan_2017`
)


SELECT * FROM `pay_detail` WHERE is_ptf = 1 AND trans_time >= '2017-01-01'
AND trans_time < '2017-02-01' AND product_no NOT IN (
SELECT product_no FROM `repayment_plan_2017`
)

#应还 ！= 实还; 如果出现 实还> 应还，那么查看还款计划是不是拆分错误，或者是不是有退款流水缺少等问题。
SELECT * FROM `repayment_plan_2017` WHERE repay_amount > 0 AND `principle` != `repay_principle`
SELECT * FROM `repayment_plan_2017` WHERE repay_amount > 0 AND `fee_amount`!= `repay_fee_amount`

# 如果有还款，则状态置为 2
SELECT * FROM `repayment_plan_2017` WHERE `repay_amount` > 0 AND STATUS = 1
# 转分期订单状态是没有还款的
SELECT * FROM `repayment_plan_2017` WHERE `repay_amount` > 0 AND STATUS = 3
# 还款为负
SELECT * FROM `repayment_plan_2017` WHERE `repay_amount` < 0


#转分期订单
select * from pay_detail where


#16年的还款计划中的数据问题: 不做任何处理，only 16年的还款放款
SELECT * FROM `repayment_plan_2016` WHERE repay_amount > require_fee AND repay_due_amount = 0
SELECT * FROM `repayment_plan_2016` WHERE repay_principle > principle



# 校验是否有流水未钩稽上
SELECT SUM(`repay_amount`) FROM `repay_detail` WHERE repay_type != 'REFUND_REPAY' AND repay_time >= '2017-01-01'
AND product_no IN (
SELECT product_no FROM `pay_detail` WHERE is_ptf = 0 AND loan_time >= '2017-01-01'
UNION
SELECT product_no FROM `pay_detail` WHERE is_ptf = 1 AND trans_time >= '2017-01-01'
)

SELECT SUM(repay_amount) FROM `repayment_plan_2017`