Use SQL to calculate two date time difference values in MySQL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.