mysql groups the field time by day and month and year

  • 2020-06-23 02:06:17
  • OfStack

Suppose there is a field time in the table, formatted as an Unix timestamp, and you now need to count the number of records per day based on that field.

Methods:

Use the convert function convert(char(10),time,120) as time, and then group by time.

How it works: The convert function converts the timestamp to the ODBC standard time (specified with the 120 parameter), then takes the first 10 bits to get the full date (excluding minutes and seconds), and then groups them.

Group method 1 sample by month and by year, only the length of the first parameter of the convert() method needs to be modified.


Related articles: