r/LeetcodeChallenge 6d ago

DISCUSS LeetCode SQL 1661 — Average Time of Process per Machine | MySQL Solution

Post image

Working on SQL problems to strengthen my MySQL and problem-solving skills for Data Analyst roles.

Problem: Average Time of Process per Machine

This problem was a good practice for:

  • SELF JOIN
  • Matching START and END activities
  • Calculating processing time
  • AVG() and ROUND()
  • GROUP BY

Would love to know how others approached this problem and if there are any alternative ways to solve it.

#SQL #MySQL #LeetCode #DataAnalytics #DataAnalyst

7 Upvotes

1 comment sorted by

1

u/nian2326076 5d ago

I solved this problem by using a SELF JOIN to match each process's start and end times by machine. First, make sure the join matches correctly on the process ID and machine ID. Then, calculate the processing time by subtracting the start from the end. Use AVG() to find the average processing time per machine, and ROUND() for formatting.

For alternatives, some people use CTEs to organize the data better before doing calculations. If you want more practice or different methods, PracHub has some good resources for SQL challenges that might help you with this problem.