Average Time of Process per Machine

2pts
Meta

Problem Statement

Operational efficiency at a data center is measured by how quickly machines complete assigned tasks. Each machine runs multiple processes, and each process has a start and end timestamp.

Write an SQL query to find the average time each machine takes to complete a process.

Rules:

  • The time to complete a process is the end timestamp minus the start timestamp.
  • The average time is calculated by taking the total time to complete all processes on the machine and dividing it by the number of processes run on that machine.
  • The resulting average time should be rounded to 3 decimal places.
  • Return the result table containing machine_id and processing_time.
  • Results must be sorted by machine_id in ascending order.
Tests your understanding of
Basic SQL, Aggregation, Self Join and Math Functions

Input Tables

activity
machine_id(INTEGER)process_id(INTEGER)activity_type(ENUM('start', 'end'))timestamp(FLOAT)
00start0.712
00end1.52
01start3.14
01end4.12
10start0.55
10end1.55
11start0.43
11end1.42
20start4.1
20end4.512
21start2.5
21end5

Expected Output

machine_id(INTEGER)processing_time(FLOAT)
00.894
10.995
21.456

Tags

EasyBasic SQLAggregationSelf JoinMath Functions
15-20 min
62%

Hints