There is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.
The time to complete a process is the 'end' timestamp
minus the 'start' timestamp
. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.
The resulting table should have the machine_id
along with the average time as processing_time
, which should be rounded to 3 decimal places.
Return the result table in any order.
The result format is in the following example.
machine_id
& process_id
의 시작 시점과 끝 시점을 찾아야했던 문제SELECT a.machine_id, ROUND(AVG(b.timestamp - a.timestamp),3) as processing_time
FROM Activity as a JOIN Activity as b
ON a.process_id = b.process_id and a.machine_id = b.machine_id
where a.activity_type = 'start' and b.activity_type = 'end'
GROUP BY 1