SQLSQL
#18

Calculate Process Duration with Activity Pair Joins in SQL

Medium
Interview Question #18

Given an `activity` table (machine_id, process_id, activity_type, timestamp), find the average processing time for each `machine_id` rounded to 3 decimal places.

Input Table: activity
4 rows preview
machine_idprocess_idactivity_typetimestamp
00start0.712
00end1.52
01start3.14
01end4.12
Expected Output Structure1 rows
machine_idprocessing_time
00.894
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us