//返回记录的同时也返回记录数select SQL_CALC_FOUND_ROWS * from user where 1=1 and salary<=2000 and salary >=1000;
//左外连接select A.ENNMCD as ENNMCD, A.INFNDT as INFNDT, A.ADUNCD as ADUNCD, A.ADUNNM as ADUNNM, A.ADUNPL as ADUNPL, A.ATRCCD as ATRCCD, A.DKCL as DKCL, A.LVBSLV as LVBSLV, A.DLBLP as DLBLP, A.ENCRZRPL as ENCRZRPL, A.ININ as ININ, G.ENNMCD as gcPrnmsr_ENNMCD, G.ENNM as gcPrnmsr_ENNM, G.BIMP as gcPrnmsr_BIMP, G.ENIMG as gcPrnmsr_ENIMG from GC_DK A LEFT JOIN GC_PRNMSR G on G.ENNMCD = A.ENNMCD
//建立索引alter table "tablename" add INDEX ("rowname");
//建立序列 CREATE SEQUENCE TEST_MEMBER_SEQUENCE MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 61 CACHE 20 NOORDER NOCYCLE
//当 compens字段为bull时 设为0 IFNULL(Compens,0)//mysql 字段相加select (SELECT COUNT(*) FROM reader_lend WHERE Reader_Id=#{reader_id}) as Alllend_times, (SELECT COUNT(*) FROM reader_violation WHERE Reader_Id=#{reader_id}) as Violations_times, (select( (SELECT IFNULL(SUM(IFNULL(amount,0)) ,0)as allMoney FROM overdue_debt WHERE Reader_Id=#{reader_id} AND Is_Income='0')+ (select IFNULL(SUM(IFNULL(Compens,0)),0) from Lose_Compens where Compens_Type='CASH' and Reader_Id=#{reader_id} and disposal='0')+ (select IFNULL(SUM(IFNULL(Penals,0)),0) from Lose_Compens where Compens_Type='CASH' and Reader_Id=#{reader_id} and disposal='0')+ (SELECT IFNULL(SUM(IFNULL(Penals,0)),0) as allPenals FROM Reader_Violation WHERE Disposal_Mode IN ("1","3") AND Disposal='0' AND Reader_Id=#{reader_id})))as AllDebtMoney from reader r left join readertype rt on rt.id=r.Reader_id LEFT JOIN overdue_debt on overdue_debt.Reader_Id=r.reader_id LEFT JOIN Lose_Compens ON Lose_Compens.Reader_Id=r.reader_id left join reader_card rc on rc.reader_id=r.reader_id where r.reader_id=#{reader_id}
//mysql 日期 NOW() 表示现在的时间 select now() from dual;
//取每组第一个select * from (select * from cust_follow ORDER BY follow_time DESC)t GROUP BY t.cust_idurl :select * from cust_follow k WHERE 1>(select count(*)FROM cust_follow where k.cust_id=cust_id and follow_time>k.follow_time);