100 % ( Moye - Moye ( Well - Explained ) ) || SQL QUERY || INNER JOIN || Beats 99.31 %
Intuition\n Describe your first thoughts on how to solve this problem. \nSELECT a1.machine_id, --> for show the machine id of Activity table...\nROUND(SUM(a2.ti
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSELECT a1.machine_id, --> for show the machine id of Activity table...\nROUND(SUM(a2.timestamp - a1.timestamp) / COUNT(*), 3) --> it helps to find average processing time...\nAS processing_time --> We take an alias as processing time for average processing time...\nFROM Activity a1 --> a1 is an alias for Activity table...\nINNER JOIN Activity a2 --> a2 is also an alias for Activity table...Both are joint with the help of INNER JOIN...\nON a1.machine_id = a2.machine_id\nAND a1.process_id = a2.process_id \nAND a1.timestamp < a2.timestamp --> Conditions given in Problem...\nGROUP BY a1.machine_id; --> grouping acc. to machine id...\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing Fundamentals of SQL...\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nSELECT a1.machine_id, \nROUND(SUM(a2.timestamp - a1.timestamp) / COUNT(*), 3) \nAS processing_time \nFROM Activity a1 \nINNER JOIN \nActivity a2 \nON a1.machine_id = a2.machine_id\nAND a1.process_id = a2.process_id \nAND a1.timestamp < a2.timestamp\nGROUP BY a1.machine_id;\n```
['Database', 'MySQL']