Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Optimize progressive computing of Datetime in MySQL

enter image description here

In the picture I have this setup where I subtract the different datetime field of the next column. I have it done, but it slows down to the point that it time-out at 200k records. Please help me optimize my SQL query.

SELECT barcode,documents.document_title, routes.receive_at, routes.release_at,
SEC_TO_TIME(
    SUM(
        TIME_TO_SEC(
            timediff(
                receive_at, (SELECT
                                 release_at 
                               FROM 
                                 routes table12
                               WHERE DATE(routes.receive_at) between  "2021-10-01" AND "2021-10-18"  and routes.id < table12.id 
                            
                               ORDER BY 
                                 id ASC 
                               LIMIT 1
                              )
                    )
            ) 
    ) 
) as time_office,
  
  SEC_TO_TIME( 
    SUM( 
        TIME_TO_SEC( 
            timediff(
                receive_at, routes.release_at
            )
        )
    )
  ) as time_travel 
from routes 
LEFT JOIN documents on routes.barcode = documents.document_code
WHERE DATE(routes.receive_at) between "2021-10-01" AND "2021-10-18"
order by  routes.id ASC
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!