Really easy solution - without any join!
Intuition\n Describe your first thoughts on how to solve this problem. \n\nSo, the question asked about the average time each machine takes to complete a proces
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nSo, the question asked about the average time each machine takes to complete a process. Therefore, what we can do is that we can group by each machine, then find all of the "start" and "end" activity, combining them together. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nFirst, we find the sum for all of the activity_type, however, when activity_type = "start" then the number is negative. \n\n```\nSELECT machine_id, ROUND(SUM(CASE WHEN activity_type = "start" THEN -timestamp\n            WHEN activity_type = "end" THEN timestamp\n            END), 3)\nAS processing_time\nFROM Activity\nGROUP BY machine_id\n```\n\nAfter finding the total sum, then what we need to do is to find the average. The easy way we can do it is to find the distinct count for the process_id, since it can show the total count easily for each machine_id. The output will be:  \n\n# Code\n```\n# Write your MySQL query statement below\nSELECT machine_id, ROUND(SUM(CASE WHEN activity_type = "start" THEN -timestamp\n            WHEN activity_type = "end" THEN timestamp\n            END) / COUNT(DISTINCT process_id), 3)\nAS processing_time\nFROM Activity\nGROUP BY machine_id\n```
['MySQL']