Simple solution with JOIN
\n\n# Code\n\n-- Write your PostgreSQL query statement below\nSELECT a1.machine_id, \n    ROUND(AVG(a1.timestamp-a2.timestamp)::numeric, 3) AS processing_time \
\n\n# Code\n```\n-- Write your PostgreSQL query statement below\nSELECT a1.machine_id, \n    ROUND(AVG(a1.timestamp-a2.timestamp)::numeric, 3) AS processing_time \nFROM Activity a1 JOIN Activity a2 ON\n    a1.machine_id=a2.machine_id\n    AND a1.process_id=a2.process_id\n    AND a1.activity_type = \'end\'\n    AND a2.activity_type = \'start\'\nGROUP BY a1.machine_id\n\n```
['PostgreSQL']