1.首先建一个表
2.在指定时间段内:
select * FROM bank_trans where transdate >='2020-1-1 00:00:00' and transdate < '2020-7-1 00:00:00';
3.近20天
select *
from bank_trans where date_sub(CURDATE(),INTERVAL 20 DAY) <= DATE(transdate);
4.本月
select *
from bank_trans where DATE_FORMAT(transdate, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' );
5.今天
select *
from bank_trans where to_days(transdate) = to_days(now());
6.查询本季度数据
select *
from bank_trans where QUARTER(transdate)=QUARTER(now());
7.-- 查询上季度数据
select *
from bank_trans where QUARTER(transdate)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));