♻️Solved in 3 different ways! | 🔝TOP 2023🤝
The following examples are solved in 3 different ways!\n\n### Your support is important to me |UPVOTE\u2B06\uFE0F|\n# Code\n\nWITH ProcessTimes AS (\n        SE
## The following examples are solved in 3 different ways!\n\n### Your support is important to me |UPVOTE\u2B06\uFE0F|\n# Code\n```\nWITH ProcessTimes AS (\n        SELECT\n        machine_id,\n        process_id,\n        SUM(CASE WHEN activity_type = \'end\' THEN timestamp ELSE -timestamp END) AS process_time\n        FROM Activity\n        GROUP BY machine_id, process_id )\nSELECT\n    machine_id,\n    ROUND(AVG(process_time), 3) AS processing_time\nFROM ProcessTimes\nGROUP BY machine_id;\n\n```\n\n---\n\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\n---\n\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```\n\n---\n\n
['MySQL']