2025-08-10 09:52:07 +0000 UTC

Average Time of Process per Machine

Code

SELECT 
    act1.machine_id, 
    ROUND(AVG(act2.timestamp - act1.timestamp)::decimal, 3) AS processing_time
FROM
    Activity act1,
    Activity act2
WHERE 
    act1.machine_id = act2.machine_id
    AND act1.process_id = act2.process_id
    AND act1.activity_type = 'start'
    AND act2.activity_type = 'end'
GROUP BY 
    act1.machine_id;