#今天 select * from or_order_task where to_days(created_date)=to_days(now());
#近七天 select * from or_order_task where date_sub(curdate(),interval 7 day )<=date(created_date);
#近七天 select * from or_order_task where date_sub(curdate(),interval 30 day )<=date(created_date);
#本月 select * from or_order_task where date_format(created_date, '%Y%m') = date_format(curdate(), '%Y%m');
#以月為緯度,取得上個月的數據 如當前時間為2018-07-02 則取數據范圍為所有數據中滿足字段名中月份為08-01至08-31的數據(可用於篩選下個月生日人員)
#數據搜索范圍可通過最后判斷的值進行調整 0為當月 1是上個月 -1為下個月 以此類推 SELECT created_date FROM or_order_task WHERE PERIOD_DIFF(DATE_FORMAT(CURDATE(),'%m'),DATE_FORMAT(created_date,'%m'))= 1;
# 以年月為維度 取得下個月數據 SELECT *FROM or_order_task WHERE PERIOD_DIFF(DATE_FORMAT(CURDATE(),'%Y%m'),DATE_FORMAT(now(),'%Y%m'))=-1
#查詢本季度數據 select * from `ticket_order_detail` where QUARTER(use_time)=QUARTER(now());
#查詢上季度數據 select * from `ticket_order_detail` where QUARTER(use_time)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));
#查詢本年數據 select * from `ticket_order_detail` where YEAR(use_time)=YEAR(NOW());
#查詢上年數據 select * from `ticket_order_detail` where year(use_time)=year(date_sub(now(),interval 1 year));
-- 查詢當前這周的數據 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now());
-- 查詢上周的數據 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now())-1;
-- 查詢當前月份的數據 select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(now(),’%Y-%m’)
-- 查詢距離當前現在6個月的數據 select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
-- 查詢上個月的數據 select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),’%Y-%m’)
-- and下月第一天 where date(regdate) = curdate(); select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now()) SELECT date( c_instime ) ,curdate( ) FROM `t_score` WHERE 1 LIMIT 0 , 30
