🌟 PostgreSQL solution 🚀 With only one GROUP BY, and one aggregator function, without JOIN 🔥
Code\n\nSELECT  machine_id,\n        ROUND(\n            AVG(\n            CASE \n                WHEN activity_type = \'start\' THEN -timestamp \n             
# Code\n```\nSELECT  machine_id,\n        ROUND(\n            AVG(\n            CASE \n                WHEN activity_type = \'start\' THEN -timestamp \n                ELSE timestamp\n            END)::decimal * 2 # there are two rows per process_id\n            , 3) AS processing_time\nFROM Activity\nGROUP BY machine_id\nORDER BY machine_id ASC;\n```\n\n> This query is more concise and might execute faster because it avoids a self-join and processes the data in a single pass. It uses a CASE statement within an aggregate function (AVG) to compute the average processing time directly.\n____\n\nIf it was useful don\'t hesitate to upvote \uD83C\uDF20 Or keep it in your favorite \uD83C\uDF1F\n![Upvote invitation](https://github.com/MathieuSoysal/CROUS-assistant-Collector/assets/43273304/b801cf95-dcda-4733-ada2-939f5fcb29e0)
['PostgreSQL']