average-time-per-machine.sql (368B)
1 --Given a list of machines and timestamps write a query 2 --that calculates the average time between the start and finish 3 --for each machine. 4 SELECT 5 s.machine_id, 6 ROUND(AVG(e.timestamp-s.timestamp),3) as processing_time 7 FROM Activity s 8 JOIN Activity e ON e.machine_id=s.machine_id 9 WHERE s.activity_type='start' AND e.activity_type='end' 10 GROUP BY s.machine_id