Mysql has Table a with the field time. If the number of days in the record span is counted, for example, n records are generated today, and m records are generated in December 1, 2015, then, we can calculate that the number is 2, only for the record to be generated today, and for the past two days, January 1, December 1, 2015 .... Mysql has Table a with the time field in the timestamp format.
If the number of days in the record span is counted, for example, if n records are generated today and m records are generated in December 1, 2015, the number of records is 2, only for today, and December 1, 2015.
For example, if there are records today, yesterday, and December 1, 2015, how can we find all the data for the 'previous three days '?
..... Then I thought of a kind ................................... ............
mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc ;+----------+-------+| day | COUNT || 20160111 | 28 || 20160109 | 41 || 20160108 | 44 || 20160107 | 52 || 20160106 | 42 || 20160105 | 49 || 20151229 | 39 || 20151228 | 35 |+----------+-------+24 rows in set
Get the array. PHP usescount(array)
Total number of days
mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc limit 0,3;+----------+-------+| day | COUNT || 20160111 | 28 || 20160109 | 41 || 20160108 | 44 |+----------+-------+3 rows in set
Obtain the statistics of the previous three days. Get the array header (20160111) and the end (20160108) into a timestamp,
$start ,$end;SELECT * FROM c_content where inputtime between $end and $start;
Reply content:
Mysql has Table a with the time field in the timestamp format.
If the number of days in the record span is counted, for example, if n records are generated today and m records are generated in December 1, 2015, the number of records is 2, only for today, and December 1, 2015.
For example, if there are records today, yesterday, and December 1, 2015, how can we find all the data for the 'previous three days '?
..... Then I thought of a kind ................................... ............
mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc ;+----------+-------+| day | COUNT || 20160111 | 28 || 20160109 | 41 || 20160108 | 44 || 20160107 | 52 || 20160106 | 42 || 20160105 | 49 || 20151229 | 39 || 20151228 | 35 |+----------+-------+24 rows in set
Get the array. PHP usescount(array)
Total number of days
mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc limit 0,3;+----------+-------+| day | COUNT || 20160111 | 28 || 20160109 | 41 || 20160108 | 44 |+----------+-------+3 rows in set
Obtain the statistics of the previous three days. Get the array header (20160111) and the end (20160108) into a timestamp,
$start ,$end;SELECT * FROM c_content where inputtime between $end and $start;
123456789