CTE: easy solution
Code
# Code
```mysql []
with tmp as (
    select 
        machine_id, 
        process_id,
        case when activity_type = 'start' then -timestamp else timestamp end as timestamp
    from Activity
)
select 
    machine_id,
    round(sum(timestamp)/count(distinct process_id), 3) as processing_time
from tmp
group by machine_id
```
['MySQL']