Easy and Simple Solution
Please Like ❤️IntuitionWe need to compute the average processing time for each machine_id by finding the time difference between start and end activities.Approa
```mysql
# Write your MySQL query statement below
select A.machine_id, round(avg(B.timestamp - A.timestamp), 3) as processing_time
from Activity as A
join Activity as B
on A.machine_id = B.machine_id 
and A.process_id = B.process_id 
and A.activity_type = 'start' 
and B.activity_type = 'end'
group by A.machine_id;
```

# Please Like ❤️  
![Please Like](https://media.tenor.com/heEyHbV8iaUAAAAM/puss-in-boots-shrek.gif)

# Intuition  
We need to compute the **average processing time** for each `machine_id` by finding the time difference between `start` and `end` activities.

# Approach  
1. **Self Join:** The table is joined with itself on the condition that both rows share the same `machine_id` and `process_id`.  
2. **Filter Conditions:** The first row (`A`) must have `activity_type = 'start'`, and the second row (`B`) must have `activity_type = 'end'`.  
3. **Processing Time Calculation:** The difference `B.timestamp - A.timestamp` gives the duration for a process.  
4. **Aggregation:** We take the `AVG` of these durations and round the result to **three decimal places**.  

# Complexity  
- **Time Complexity**:  
  $$O(n)$$ if indexed properly, otherwise $$O(n^2)$$ due to the self-join.  
- **Space Complexity**:  
  $$O(1)$$ as we do not use additional data structures apart from query execution.
['MySQL']