MySQL Query this quarter
Today
SELECT * FROM table name where To_days (Time field name) = To_days (now ());
Yesterday
SELECT *from table name where To_days (now ()) –to_days (Time field name) <= 1
7 days
SELECT *from table name where Date_sub (Curdate (), INTERVAL 7 day) <= Date (Time field name)
Nearly 30 days
SELECT *from table name where Date_sub (Curdate (), INTERVAL Day) <= Date (Time field name)
Month
SELECT *from table name where Date_format (Time field name, '%y%m ') = Date_format (Curdate (), '%y%m ')
Last month
SELECT *from table name WHERE Period_diff (Date_format (now (), '%y%m '), Date_format (Time field name, '%y%m ')) =1
#查询本季度数据
SELECT * from ' ht_invoice_information ' Wherequarter (create_date) =quarter (now ());
#查询上季度数据
SELECT * from ' ht_invoice_information ' Wherequarter (create_date) =quarter (Date_sub (now (), Interval 1QUARTER));
#查询本年数据
SELECT * from ' ht_invoice_information ' Whereyear (create_date) =year (now ());
#查询上年数据
SELECT * from ' ht_invoice_information ' Whereyear (create_date) =year (Date_sub (now (), interval 1));
Querying data for the current week
SELECT Name,submittime from Enterprise Whereyearweek (Date_format (submittime, '%y-%m-%d ')) =yearweek (now ());
Query last week's data
SELECT Name,submittime from Enterprise Whereyearweek (Date_format (submittime, '%y-%m-%d ')) =yearweek (now ())-1;
Querying data for the current month
Select Name,submittime fromenterprise wheredate_format (submittime, '%y-%m ') =date_format (now (), '%y-%m ')
Query data that is currently 6 months from now
Select Name,submittime from Enterprise where Submittime betweendate_sub (now (), Interval 6 month) and now ();
Querying data for the previous month
Select Name,submittime fromenterprise wheredate_format (submittime, '%y-%m ') =date_format (Date_sub (Curdate (), INTERVAL 1 MONTH), '%y-%m ')
Select*from ' user ' Wheredate_format (pudate, '%y%m ') =date_format (Curdate (), '%y%m ');
SELECT * from User whereweekofyear (From_unixtime (pudate, '%y-%m-%d ')) =weekofyear (now ())
select*
Fromuser
Wheremonth (From_unixtime (pudate, '%y-%m-%d ')) =month (now ())
select*
From[user]
Whereyear (From_unixtime (pudate, '%y-%m-%d ')) =year (now ())
Andmonth (From_unixtime (pudate, '%y-%m-%d ')) =month (now ())
select*
From[user]
Wherepudatebetween last day of the month
And the first day of next month
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
MySQL query today's data for this month yesterday