Recently done a set of record system, the record to query by day, how many points won every day, how many innings to list. However, how to use SQL to group by day? First of all, our table confirms that we have a timestamp (int (10)), and I use Create_time.
Next, start editing the statement
The From_unixtime function supports converting timestamps to strings, and we convert timestamps to dates
From_unixtime (Create_time, '%y%m month%d day ')
Then, grouped by this date, here's the full SQL statement
Select From_unixtime (create_time, '%y year%m month%d days ') as Day,count (*) as Count,sum (score) as score from T_everygames where user _id = $userid GROUP by from_unixtime (Create_time, '%y year%m month%d day ') Order by 1 limit 0,6
Similarly, can also according to year, month, day, time, cent to group, is not very convenient?
If a string is stored in the database, such as 2018-1-30, then the Date_format () function is used.