Get daily statistics When doing a project, you need to analyze the project log. One of the requirements is to obtain the log data of each day in a given time period. For example, you need to obtain the log data of each day from 2018-02-02 09:18:36 to 2018-03-05 23:18:36. Generally, when you see this requirement, you consider using functions to solve it, and directly use SQL statements. SELECT DATE_FORMAT(trigger_time, '%Y-%m-%d') triggerDay, COUNT(id) triggerCount FROM `job_qrtz_trigger_log` WHERE trigger_time BETWEEN '2018-02-02 09:18:36' AND '2018-03-05 23:18:36' GROUP BY triggerDay ORDER BY trigger_time; Query results: A brief explanation of the above sql First, query the field. Here, COUNT(id) triggerCount is the number of statistical data we need. You can add required fields according to actual needs. DATE_FORMAT(trigger_time, '%Y-%m-%d') triggerDay This is a date formatted into the format of YYYY-mm-dd. The format here is used for subsequent grouping, so you can customize the format according to different needs. My requirement is to get the log data for each day, so I group them in the format of year-month-date and get them through count(*). If you want to get the amount of data for each month in a certain month, change the format to DATE_FORMAT(trigger_time, '%Y-%m') Of course, the where condition needs to match the format. You cannot limit the where condition to the date and group by month. The date output format of MySQL is listed below: %a abbreviated day of the week Get statistics for each hour of a day Use the HOUR function that comes with Mysql to process SELECT HOUR(trigger_time) as Hour,count(*) as Count FROM xxl_job_qrtz_trigger_log WHERE trigger_time BETWEEN '2018-02-05 01:18:36' AND '2018-02-05 17:18:36' GROUP BY HOUR(trigger_time) ORDER BY Hour(trigger_time); The query results are as follows The above is the detailed explanation and integration of MySQL to obtain statistical data for every day and every hour in a certain period of time introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
>>: vue+rem custom carousel effect
I rewrote my personal website recently. I bought ...
Table of contents For example: General writing: S...
1. Background Generally, in a data warehouse envi...
Summarize 1. Similarities Both can change the int...
Table of contents 1. Preparation 2. MySQL encrypt...
Preface: One day, I built a MySQL service in Dock...
By default, the border of the table is 0, and we ...
There are many form elements. Here is a brief sum...
The effect to be achieved is: fixed zoom in twice...
Blank's blog: http://www.planabc.net/ The use...
Table of contents 1. Preprocessing 2. Pretreatmen...
I believe that many users who make websites will ...
background When I was using Docker these two days...
<br />Original article: http://www.alistapar...
Introduction to NFS NFS (Network File System) is ...