Home > database >  Mysql database to record timestamp values how to query by the hour
Mysql database to record timestamp values how to query by the hour

Time:10-27


Such as a database, id, username, time three columns,
One time 10 timestamp to record the user registration time.
Now in order to query the total number of registered per hour a day, seven days a week (not to separate each week),
Such as a database for all records on Monday 0:00 ~ 0:59 how much is the number of registered users;
How much is 1:00 ~ it happened to register the number of users;
.
On Tuesday, 0:00 ~ 0:59 registered how much is the number of users;
.
Sunday: 23:00 ~ 23:59 registered how much is the number of users,
The SQL statement should be how to write?

CodePudding user response:

Use the date_format

Per hour statistics:
The select date_format (date, '% Y - m - H % d % %') as d, count (*) from table group by d

CodePudding user response:

Statistical demand real-time check, it is best not to make a table to save more, if you use SQL, but it was formatted
  • Related