The damn mysql does not provide a dedicated unix timestamp processing function. Therefore, if you encounter a time group and you use an integer unix timestamp, only other date types of mysql can be converted! FROM_UNIXTIM () converts unix timestamp to datetime type! 1. query data of the current year using the annual query SELECT * FROMblog_articleW
The damn mysql does not provide a dedicated unix timestamp processing function. Therefore, if you encounter a time group and you use an integer unix timestamp, only other date types of mysql can be converted! FROM_UNIXTIM () converts unix timestamp to datetime type! 1. query the data of the current year by querying the annual data SELECT * FROM blog_article W
The damn mysql does not provide a dedicated unix timestamp processing function. Therefore, if you encounter a time group and you use an integer unix timestamp, only other date types of mysql can be converted!
FROM_UNIXTIM () converts unix timestamp to datetime type!
1. Annual Query
Query data of the current year
SELECT *
FROM blog_article
WHERE year (FROM_UNIXTIME (BlogCreateTime) = year (curdate ())
Ii. query quarterly data
Query the number of accompanying quarters of data
SELECT ArticleId, quarter (FROM_UNIXTIME ('blogcreatetime '))
FROM 'blog _ article'
Others are the same as those in the previous section: query data for the current quarter
SELECT *
FROM blog_article
WHERE quarter (FROM_UNIXTIME (BlogCreateTime) = quarter (curdate ())
3. query monthly data
Statistics for this month (MySQL)
Select * from booking where month (booking_time) =
Month (curdate () and year (booking_time) = year (curdate ())
Weekly Statistics (MySQL)
Select * from spf_booking where month (booking_time) =
Month (curdate () and week (booking_time) = week (curdate ())
Iv. Time Period
Records within N days
WHERE TO_DAYS (NOW ()-TO_DAYS (time field) <= N
Today's records
Where date (time field) = date (now ())
Or
Where to_days (time field) = to_days (now ());
Query for one week:
Select * from table where DATE_SUB (CURDATE (), INTERVAL7DAY) <= date (column_time );
Query for one month:
Select * from table where DATE_SUB (CURDATE (), INTERVAL1MONTH) <= date (column_time );
Query all birthday members from '06-03' to '07-08:
Select * From user Where
DATE_FORMAT (birthday, '% m-% D')> = '06-03' and DATE_FORMAT (birthday, '% m-% D ')
<= '07-08 ';
Calculate the first quarter data. The table time field is 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) DIV3) +1;
V. group query
1. Annual Group
2. Monthly grouping
3. Group by year and then by monthly
4. Group by month/year
SELECT count (ArticleId), date_format (FROM_UNIXTIME ('blogcreatetime'), '% y % m') sdate FROM 'blog _ article' group by sdate
Result:
Count (ArticleId) sdate
17 0901
11 0902
5 0903
6 0904
2 0905
1 0907
12 0908
6 0909
11 0910
3 0911