STEP BY STEP SOLUTION 🔥🔥🔥
ApproachCode/if you like it please upvote it./
# Approach
<!-- Describe your approach to solving the problem. --> CTE, SQL BASIC FUNCTION


# Code
```mssql []
/* Write your T-SQL query statement below */
/*First calculate how long each process took to complete. */
WITH processDuration AS(
    SELECT machine_id , process_id ,
    MAX(CASE WHEN activity_type = 'END' THEN timestamp ELSE NULL END ) - 
    MIN(CASE WHEN activity_type = 'START' THEN timestamp ELSE NULL END ) AS DURATION
    FROM Activity 
    GROUP BY machine_id , process_id 
),
/*Here we calculate the average*/
averageTime AS(

    SELECT machine_id, AVG(DURATION) AS 'processing_time'
    FROM processDuration 
    GROUP BY machine_id
)
/*Finally we round up the value*/
SELECT machine_id, ROUND(processing_time, 3) AS 'processing_time'
FROM averageTime
```
/*if you like it please upvote it.*/


['MS SQL Server']