SQL ✅ | JOIN or Subquery ✅✅| Easy to understand
Intuition\nThe paste was solved in 2 different ways.\nIn the first one, a solution based on \'join\' is achieved (which is more self-explanatory)\nIn the second
# Intuition\n***The paste was solved in 2 different ways.\nIn the first one, a solution based on \'join\' is achieved (which is more self-explanatory)\nIn the second one, the solution is achieved through subqueries (This solution is also understandable and wonderful)***\n\n\n![image.png](https://assets.leetcode.com/users/images/c0d84b6d-15b9-43c1-b31d-999d38c4781e_1688555463.4935868.png)\n\n# First Solution\n```\nselect a1.machine_id, round(avg(a2.timestamp-a1.timestamp), 3) as processing_time \nfrom Activity a1\njoin Activity a2 \non a1.machine_id=a2.machine_id and a1.process_id=a2.process_id\nand a1.activity_type=\'start\' and a2.activity_type=\'end\'\ngroup by a1.machine_id\n\n```\n# Second Solution\n```\nselect \na.machine_id,\nround(\n      (select avg(a1.timestamp) from Activity a1 where a1.activity_type = \'end\' and a1.machine_id = a.machine_id) - \n      (select avg(a1.timestamp) from Activity a1 where a1.activity_type = \'start\' and a1.machine_id = a.machine_id)\n,3) as processing_time\nfrom Activity a\ngroup by a.machine_id\n```
['Database', 'MySQL']