MySQL Query SQL code for this week, last week, this month, and last month's data
Font: [Increase decrease] Type: Reprint time: 2012-11-29 I want to comment
MySQL query a lot of ways, the following for you to introduce the MySQL query is to query this week, last week, this month, the last month's data, if you are interested in MySQL query, may wish to look at today's SQL
Yesterday SQL
querying data for the current week
SELECT Name,submittime from the Enterprise WHERE Yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ());
query last week's data
SELECT Name,submittime from the Enterprise WHERE Yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ())-1;
querying data for the current month
Select Name,submittime from Enterprise where Date_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 between Date_sub (now (), Interval 6 month) and now ();
querying data for the previous month
Select Name,submittime from Enterprise where Date_format (Submittime, '%y-%m ') =date_format (Date_sub (Curdate (), INTERVAL 1 MONTH), '%y-%m ')
SELECT * from ' user ' where Date_format (pudate, '%y%m ') = Date_format (Curdate (), '%y%m ');
SELECT * from user where WeekOfYear (from_unixtime (pudate, '%y-%m-%d ')) = WeekOfYear (now ())
SELECT *
From user
Where month (From_unixtime (pudate, '%y-%m-%d ')) = month (now ())
SELECT *
from [user]
Where year (From_unixtime (pudate, '%y-%m-%d ')) = year (now ())
And month (From_unixtime (pudate, '%y-%m-%d ')) = month (now ())
SELECT *
from [user]
Where pudate between the last day of last month
And the first day of next month
MySQL query SQL code for data today/yesterday/this week, last week, month, month