Why make it complicated? Easiest solution ever!
\nSELECT \n    machine_id,\n    ROUND(AVG(IF(activity_type = "end", timestamp, -timestamp)) * 2, 3) AS processing_time\nFROM Activity\nGROUP BY machine_id;\n
```\nSELECT \n    machine_id,\n    ROUND(AVG(IF(activity_type = "end", timestamp, -timestamp)) * 2, 3) AS processing_time\nFROM Activity\nGROUP BY machine_id;\n```
[]