AnalystPath

Machines With Quick Back-to-Back Runs

SQLHardSenior level~15 min

Problem

Table `Runs` logs production runs on factory machines: `machine_id`, `run_start` and `run_end` (datetimes), a unique `run_id`, and a `job_type` (such as `Mold` or `Cut`). A run is 'quick back-to-back' when the same machine starts another run of the same `job_type` no more than 8 hours after the previous run of that same type ended.

Find every machine that has at least one quick back-to-back run. Return the distinct `machine_id`, ordered ascending.

Tables

Example rows — the live problem includes the full dataset.

Runs
machine_idrun_startrun_endrun_idjob_type
1012024-03-01 08:00:002024-03-01 09:00:001Mold
1012024-03-01 10:00:002024-03-01 11:00:002Cut
1022024-03-01 13:00:002024-03-01 14:00:003Mold

Expected output

Your answer should return 1 row with the columns machine_id.

Starter code (SQL)

SELECT *
FROM Runs;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions