The Fast Lane

A medium SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
medium
Seniority
L3
Asked in
Travelport

Problem

The data platform team is benchmarking the pipelines that finish quickly, those that complete in 45 minutes or less (2700 seconds). For each of those pipelines, find the average rows output, sorted from the highest average to the lowest.

Only the quick runs make the cut. Measure what they move.

Tables

data_pipes

Columns: pipe_id INTEGER, pipe_name TEXT, status TEXT, rows_in INTEGER, rows_out INTEGER, start_at TEXT, dur_secs INTEGER

data_pipes: 10 of 200 rows
pipe_idpipe_namestatusrows_inrows_outstart_atdur_secs
131etl_usersfailed137972026-02-02 01:00:0028
162etl_eventsrunning2741942026-03-03 02:00:0051
193sync_crmqueued4112912026-04-04 03:00:0074
224agg_dailyskipped5483882026-05-05 04:00:0097
255agg_weeklySuccess6854852026-06-06 05:00:00NULL
286export_s3FAILED8225822026-07-07 06:00:00143
317import_csvsuccessNULL6792026-08-08 07:00:00166
348ml_trainfailed10967762026-09-09 08:00:00189
379dbt_buildrunning1233NULL2026-01-10 09:00:00212
410etl_ordersqueued13709702026-02-11 10:00:00NULL

Expected output

First 5 of 8 rows
pipe_nameavg_rows_out
ml_train5518.222222222223
import_csv5313.444444444444
agg_daily4699.111111111111
export_s34612.777777777777
dbt_build4401.25

Worked solution and explanation

What this really is

Strip the benchmarking language and this is a filtered group average wearing a costume. Keep the runs that finished inside the time window, bucket them by pipeline name, average rows_out, and sort. The whole problem turns on one quiet decision the prompt never spells out: what happens to the runs where dur_secs is NULL. A run that never recorded a duration is not a fast run, and that is exactly where candidates either quietly do the right thing or quietly break it.


Building it

Step 1: Filter to the window

Cut to the fast runs with dur_secs BETWEEN 0 AND 2700. The lower bound of 0 keeps the intent honest (a duration cannot be negative) and the upper bound is the 45-minute ceiling, inclusive, so a run at exactly 2700 seconds counts. NULL durations fall away for free, no explicit IS NOT NULL needed.

Step 2: Bucket by pipeline

Collapse the surviving runs by pipe_name so each pipeline becomes one row in the output. pipe_id is unique per run, so grouping by it would give one row per run.

Step 3: Average and sort

Take AVG(rows_out) per bucket. AVG skips NULL rows_out automatically, so a run that logged no output count does not drag the average toward zero, it simply does not participate. Order by that average, highest first.


The solution

Filtered average per pipeline
SELECT pipe_name, AVG(rows_out) AS avg_rows_out
FROM data_pipes
WHERE dur_secs BETWEEN 0 AND 2700
GROUP BY pipe_name
ORDER BY avg_rows_out DESC
Looks careful, is wrong
COALESCE(dur_secs, 0) BETWEEN 0 AND 2700 pulls every NULL-duration run into the fast set, adding etl_orders and agg_weekly with averages built from runs that never reported how long they took.
Correct
Plain dur_secs BETWEEN 0 AND 2700 lets NULL durations evaluate to NULL and drop out, so only genuinely fast runs reach the average.

Common follow-up questions