Recently encountered a problem: the development-time table does not have a time stamp that is used directly for the day month field, but it is counted by days, months, and years
This without program processing directly with MySQL can handle:
MySQL does not have a specialized processing function for UNIX timestamps, so if you encounter time groupings and you are using an integer UNIX timestamp, then only the other date types that are converted to MySQL!
From_unixtim () converts a Unix timestamp to a datetime date type!
I. Annual ENQUIRY
Querying data for the year
SELECT *
From Blog_article
WHERE year (From_unixtime (blogcreatetime)) = year (Curdate ())
Second, query quarterly data
Number of quarters with query data included
SELECT ArticleID, Quarter (from_unixtime (' Blogcreatetime '))
From ' Blog_article '
Other previous sections: Querying data for the quarter
SELECT *
From Blog_article
WHERE Quarter (From_unixtime (blogcreatetime)) = Quarter (Curdate ())
Third, query monthly data
Monthly Statistics (MySQL)
SELECT * FROM booking where month (booking_time) =
Month (Curdate ()) and year (booking_time) = year (Curdate ())
Weekly Stats (MySQL)
SELECT * FROM spf_booking where month (booking_time) =
Month (Curdate ()) and week (booking_time) = Week (Curdate ())
Iv. time period
N Days of recording
WHERE To_days (now ())-To_days (Time field) <= N
Record of the day
Where date (Time field) =date (now ())
Or
Where To_days (Time field) = To_days (now ());
Query one week:
SELECT * FROM table where Date_sub (Curdate (), INTERVAL 7 day) <= DATE (column_time);
Query one months:
SELECT * FROM table where Date_sub (Curdate (), INTERVAL INTERVAL 1 MONTH) <= DATE (column_time);
Query ' 06-03 ' to ' 07-08 ' for all birthdays during this time period:
Select * from user Where
Date_format (Birthday, '%m-%d ') >= ' 06-03 ' and date_format (birthday, '%m-%d ')
<= ' 07-08 ';
Statistics quarterly data, table Time field: Savetime
Group BY Concat (Date_format (savetime, '%Y '), Floor ((Date_format (savetime, '%m ') +2)/3))
Or
Select year (savetime) *10+ ((MONTH (Savetime)-1) DIV 3) +1,count (*)
From yourtable
Group by year (Savetime) *10+ ((MONTH (Savetime)-1) DIV 3) +1;
Five, group query
1. Group of the Year
2. Monthly Group
3, first group by year, and then by the monthly group
4. GROUP BY month
SELECT count (ArticleID), Date_format (From_unixtime (' blogcreatetime '), '%y%m ') sdate from ' Blog_article ' GROUP by sdate
Results:
Count (ArticleID) sdate
17 0901
11 0902
5 0903
6 0904
2 0905
1 0907
12 0908
6 0909
11 0910
3 0911
Mysql by year, quarter, month, week, day SQL statistics query