Easiest solution you can ever find!
ApproachGroup the table by machine_id and then activity_type and then fetch the sum of same timestamps and also the count of machines now this will act as our t
# Approach
Group the table by machine_id and then activity_type and then fetch the sum of same timestamps and also the count of machines now this will act as our table t1, which we will group by the machine ids and then calculate the max and min which is sum of all start times and sum of end times and then averaging it over the total number of machines to get the final answer.

# Code
```mysql []
SELECT machine_id, ROUND((MAX(times)-MIN(times))/machine_cnt, 3) as processing_time
FROM (SELECT machine_id, SUM(Activity.timestamp) AS times, COUNT(machine_id) AS machine_cnt FROM Activity GROUP BY machine_id, activity_type) AS t1 
GROUP BY machine_id;
```
['MySQL']