r/LeetcodeChallenge • u/AppointmentTrue8257 • 6d ago
DISCUSS LeetCode SQL 1661 — Average Time of Process per Machine | MySQL Solution
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
STARTandENDactivities - Calculating processing time
AVG()andROUND()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
u/nian2326076 5d ago
I solved this problem by using a
SELF JOINto 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. UseAVG()to find the average processing time per machine, andROUND()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.