Direct Approach using CASE 🔥
IntuitionUses a CASE statement to sum timestamps:
start activities are subtracted (-timestamp).
stop activities are added (+timestamp).
This effectively compute
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Uses a **CASE statement** to sum timestamps:
start activities are subtracted (-timestamp).
stop activities are added (+timestamp).
This effectively computes the total processing time for each machine.

# Code
```postgresql []

with cte as (
select machine_id , sum(
case when activity_type='start' then -timestamp
else timestamp end ) as summer , count(*)/2 as process
from activity
group by machine_id
)

select machine_id , round ((summer/process)::NUMERIC,3) as processing_time from cte;
```
['PostgreSQL']