需要注意的一些Mysql语句
1. 日期处理函数:date_format()
select COUNT(*) from (SELECT
SERIAL_NO,
APPLY_SERIAL_NO,
FLAG,
PAY_DATE,
SEQ_ID,
FINISH_DATE,
INSERT_DATE,
UPDATE_DATE
FROM
NY_REPAY_PLAN
WHERE
PAY_DATE < '2017-01-22'
AND FINISH_DATE IS NULL
)
tp where date_format(tp.PAY_DATE, '%d') not in (15,25) ORDER BY PAY_DATE DESC;
2.时间互转说明:
FLOW_NO,格式如下:NYB01-170114-663268
select count(*) from QH_VERIFY where str_to_date(concat("20",substring(FLOW_NO,7,6)),"%Y%m%d")>="2017-02-01";
3. 多表之间更新数据,效率最优:
update
(NY_REPAY_PLAN tbl1 join test_nydata2 tbl2 on tbl1.SERIAL_NO=tbl2.SCHEDULE_SERIAL_NO)
set tbl1.FINISH_DATE=tbl2.FINISH_DATE where tbl1.PAY_DATE<'2017-02-02' AND tbl1.FINISH_DATE IS NULL;
3.数据导入和单表匹配
LOAD DATA INFILE '/usr/local/mysql/PaySchedule0200120170115.txt.txt' INTO TABLE NY_PAYSCHEDULE FIELDS TERMINATED BY '|';
update(NY_EARLY_REPAY t4 left join(select t1.APPLY_SERIAL_NO,t2.ACCOUNT_NO,t2.LOAN_NO,t2.ORDER_ID from NY_PASSCONTRACT t1 join NY_LOAN t2 on t1.CONTRACT_NO=t2.CONTRACT_NO)t3 on t4.ALSERIAL_NO=t3.LOAN_NO) set t4.APPLY_SERIAL_NO=t3.APPLY_SERIAL_NO,t4.ACCOUNT_NO=t3.ACCOUNT_NO,t4.ORDER_ID=t3.ORDER_ID ;
INSERT NY_REPAY_PLAN_BAK3(FLAG,SERIAL_NO,ALSERIAL_NO,SEQ_ID,PAY_DATE,PAY_TYPE,INTE_DATE,PAY_CORPUS_AMT,PAY_INTE_AMT,PAY_FEE_AMT,PAY_FINE_AMT,PAY_COMPDINTE_AMT,FEE_TYPE,CORPUS_BALANCE,ACTUAL_PAY_CORPUS_AMT,ACTUAL_PAY_INTE_AMT,ACTUAL_PAY_FEE_AMT,ACTUAL_FINE_AMT,ACTUAL_COMPDINTE_AMT,DEFAULT_PAY_ACCT_NO,FINISH_DATE,APPLY_SERIAL_NO,ACCOUNT_NO,ORDER_ID,INSERT_DATE,UPDATE_DATE)
SELECT FLAG,SERIAL_NO,ALSERIAL_NO,SEQ_ID,PAY_DATE,PAY_TYPE,INTE_DATE,PAY_CORPUS_AMT,PAY_INTE_AMT,PAY_FEE_AMT,PAY_FINE_AMT,PAY_COMPDINTE_AMT,FEE_TYPE,CORPUS_BALANCE,ACTUAL_PAY_CORPUS_AMT,ACTUAL_PAY_INTE_AMT,ACTUAL_PAY_FEE_AMT,ACTUAL_FINE_AMT,ACTUAL_COMPDINTE_AMT,DEFAULT_PAY_ACCT_NO,FINISH_DATE,APPLY_SERIAL_NO,ACCOUNT_NO,ORDER_ID,INSERT_DATE,UPDATE_DATE FROM NY_EARLY_REPAY;