MySql calculates every day, every hour, every minute, and every minute in a period of time.
Statistics on each day in a period of time or at each time point are usually calculated. However, mysql itself does not directly obtain the time point list function or table. The following are some of the methods used by you to associate a temporary variable with an existing table that has more data (depending on the actual situation) to obtain the time point list. Hope to help you.
Some key data used in SQL
# T_table is an existing table with more data on the system.
Every day of a month
# SET @ beginDate = '2017-07-01 '; SET @ maxDate = '2017-07-31'; select date (@ tempDay), @ tempDay: = DATE_ADD (@ tempDay, INTERVAL 1 DAY) FROM t_table f # This table is an existing table with more data in the system, left join (SELECT @ tempDay: = @ beginDate) B ON 1 = 1 WHERE @ tempDay <= @ maxDate
Every hour of yesterday
# SET @ beginDate = DATE (DATE_ADD (NOW (), INTERVAL-1 DAY); SET @ maxDate = DATE (NOW ()); SELECT DATE_FORMAT (@ tempHour, '% H'), @ tempHour: = DATE_ADD (@ tempHour, INTERVAL 1 HOUR) FROM t_table fLEFT JOIN (SELECT @ tempHour: = @ beginDate) B ON 1 = 1 WHERE @ tempHour <@ maxDate
Every minute in an hour
# SET @ beginDate = '2017-08-01 17:00:00 'every minute in an hour; SET @ maxDate = '2017-08-01 18:00:00'; SELECT DATE_FORMAT (@ tempMinute, '% I'), @ tempMinute: = DATE_ADD (@ tempMinute, INTERVAL 1 MINUTE) FROM t_table tLEFT JOIN (SELECT @ tempMinute: = @ beginDate) B ON 1 = 1 WHERE @ tempMinute <@ maxDate