LeetCode solutions

1801. Average Time of Process per Machine

My accepted SQL solution to LeetCode problem 1801, Average Time of Process per Machine, running in 215ms.

  • Difficulty: Easy
  • SQL
  • Runtime 215ms
  • Memory 0.0B

Read the problem on LeetCode View on GitHub

SQL

Accepted on LeetCode — runtime 215ms, memory 0.0B, accepted 2025-12-31.

sql
SELECT a1.machine_id, 
       ROUND(AVG(a2.timestamp - a1.timestamp), 3) AS processing_time
FROM Activity a1
JOIN Activity a2 
    ON a1.machine_id = a2.machine_id 
    AND a1.process_id = a2.process_id
    AND a1.activity_type = 'start' 
    AND a2.activity_type = 'end'
GROUP BY a1.machine_id

Source