25. Average Time of Process per Machine
https://leetcode.com/problems/average-time-of-process-per-machine/submissions/1449118058/
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.
select a.machine_id, round(avg(b.timestamp-a.timestamp),3) processing_time from activity a join activity b on a.machine_id=b.machine_id and a.process_id=b.process_id and a.activity_type='start' and b.activity_type='end' group by a.machine_id
Join을 통해 end_time과 start_time을 만들어서 평균시간을 구할 수 있다. 다만, 평균에 대해서 한번 더 생각해보기!