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
1: If you use the tag <a> to link to a page,...
This article example shares the specific code of ...
This article shares with you how to use Navicat t...
Table of contents Preface 1. Define label style 2...
Table of contents Combining lookahead and lookbeh...
Table of contents 1. Introduction to the Implemen...
What is the main function of Docker? At present, ...
The <link> tag defines the relationship bet...
Newer Linux distributions no longer have the rc.l...
Table of contents Overview What are callbacks or ...
1. What is ElasticSearch? Elasticsearch is also d...
Table of contents Creating HTML Pages Implement t...
Introduction: Lambda Probe (formerly known as Tom...
The main functions are as follows: Add product in...
/****************** * Advanced character device d...