No Joins | No SubQuery | Easy Solution
\n# Approach\n\nCalculate the time take by processes to complete\nby the formula given in question \n\nthen divide it by count() / 2  \n\ncount() will give pair
\n# Approach\n\nCalculate the time take by processes to complete\nby the formula given in question \n\nthen divide it by count(*) / 2  \n\ncount(*) will give pairs (start,end) for a  process\ndivide it by 2 to get no. of processes\n\nat the end group iy by machine_id to get machine wise avg time\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Write your MySQL query statement below\n\n select machine_id ,\n\n Round(\n\n    ( sum(case when activity_type = \'end\' then timestamp else 0 end) - \n     sum(case when activity_type = \'start\' then timestamp else 0 end) ) / (count(*)/2)\n     \n\n     ,3\n ) as processing_time\n\n from activity\n group by machine_id;\n```
['MySQL']