Leetcode Problem 1661. Average Time of Process per Machine

1661. Average Time of Process per Machine

Leetcode Solutions

Calculating Average Process Time per Machine

  1. Select all records from the Activity table and alias it as a for 'start' timestamps and b for 'end' timestamps.
  2. Join a and b on machine_id and process_id where a.activity_type is 'start' and b.activity_type is 'end'.
  3. Calculate the time difference for each process by subtracting a.timestamp from b.timestamp.
  4. Group the results by machine_id.
  5. Calculate the average processing time for each group.
  6. Round the average processing time to three decimal places.
  7. Select machine_id and the calculated average processing time as processing_time.
erDiagram
    Activity {
        int machine_id
        int process_id
        enum activity_type
        float timestamp
    }

Calculating Average Process Time per Machine Using Conditional Aggregation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...