Requirements Description:
1, in the project need to calculate the duration of a link and the number of times of the link.
2, the requirement duration in minutes to display, and count the number of times.
How to resolve:
It is determined by calculating the difference in the number of seconds between the start time and the end time of a link.
Code section:
Description: The database uses MySQL, and the persistence layer framework uses MyBatis.
The code is as follows:
Floor ((SUM (Unix_timestamp (start)-unix_timestamp (end time))/COUNT (number of executions))/60) as Averagetime
Code Description:
1, Unix_timestamp ()
Return value: The number of seconds from ' 1970-01-01 00:00:00 ' to the current time, and the unit conversion is required if the number of milliseconds is calculated.
2, (SUM (Unix_timestamp (Start time)-unix_timestamp (end time))/COUNT (number of executions))/60)
Return value: The average execution time (in minutes) of a link.
3. Floor ()
Return value: The function returns only the integer part, and the fractional part is discarded.
Summary: The above code only calculates the difference between two dates, and does not describe the overall sorting and grouping of data queries.
Use SQL to calculate two date time difference values in MySQL