MYSQL Query Day, this week, the last 7 days, this month, the last 30 days of statementsOriginal April 13, 2017 16:40:38
-The day
SELECT * from table name wherewhere= to_days (now ());
--This week
SELECT * FROM table name WHERE Yearweek (date_format (Time field, '%y-%m-%d ')) = Yearweek (now ());
--Last 7 days
SELECT * FROM table name where Date_sub (Curdate (), INTERVAL 7 day) <= Date (Time field);
--This month
SELECT * FROM table name where Date_format (Time field, '%y%m ') = Date_format (Curdate (), '%y%m ');
--Last 30 days
SELECT * FROM table name WHERE date_sub (Curdate (), INTERVAL Day) <= date (Time field);
--Last month
SELECT *fromWHERE'%y%m'%y%m' = 1
--This quarterSELECT * from table name WHERE QUARTER (create_date)=QUARTER (now ());
Query last quarter data
SELECT * FROM table name WHERE QUARTER (create_date)=1 QUARTER));
Query this year's data
SELECT * FROM table name WHEREYear (create_date)= Year (now ());
Query last year data
SELECT * FROM table name WHEREYear (create_date)= Year1));
query data for last week
select * from table name WHERE Span style= "COLOR: #0000ff" > Yearweek (date_format (Submittime, " %y-%m-%d ") = Yearweek (now ()) - 1 ;
Querying data for the previous month
SELECT * FROM table name WHEREDate_format (Submittime,'%y-%m')=Date_format (Date_sub (Curdate (), INTERVAL1 MONTH),'%y-%m') SELECT * FROM table name WHEREDate_format (Pudate,'%y%m')=Date_format (Curdate (),'%y%m') ; SELECT * FROM table name WHEREWeekOfYear (From_unixtime (Pudate,'%y-%m-%d'))=WeekOfYear (now ()) SELECT * FROM table name WHERE MONTH(From_unixtime (Pudate,'%y-%m-%d'))= MONTH(now ()) SELECT * FROM table name WHERE Year(From_unixtime (Pudate,'%y-%m-%d'))= Year(Now ()) and MONTH(From_unixtime (Pudate,'%y-%m-%d'))= MONTH(now ()) SELECT * FROM table name WHEREPudatebetweenLast day of last month andThe first day of next month
Query data that is currently 6 months from now
SELECT * FROM table name WHEREbetween 6 Month and now ();
MYSQL Query Day, this week, the last 7 days, this month, the last 30 days of statements