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
| pipe_id | pipe_name | status | rows_in | rows_out | start_at | dur_secs |
|---|---|---|---|---|---|---|
| 131 | etl_users | failed | 137 | 97 | 2026-02-02 01:00:00 | 28 |
| 162 | etl_events | running | 274 | 194 | 2026-03-03 02:00:00 | 51 |
| 193 | sync_crm | queued | 411 | 291 | 2026-04-04 03:00:00 | 74 |
| 224 | agg_daily | skipped | 548 | 388 | 2026-05-05 04:00:00 | 97 |
| 255 | agg_weekly | Success | 685 | 485 | 2026-06-06 05:00:00 | NULL |
| 286 | export_s3 | FAILED | 822 | 582 | 2026-07-07 06:00:00 | 143 |
| 317 | import_csv | success | NULL | 679 | 2026-08-08 07:00:00 | 166 |
| 348 | ml_train | failed | 1096 | 776 | 2026-09-09 08:00:00 | 189 |
| 379 | dbt_build | running | 1233 | NULL | 2026-01-10 09:00:00 | 212 |
| 410 | etl_orders | queued | 1370 | 970 | 2026-02-11 10:00:00 | NULL |
Expected output
| pipe_name | avg_rows_out |
|---|---|
| ml_train | 5518.222222222223 |
| import_csv | 5313.444444444444 |
| agg_daily | 4699.111111111111 |
| export_s3 | 4612.777777777777 |
| dbt_build | 4401.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
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 2700pulls every NULL-duration run into the fast set, addingetl_ordersandagg_weeklywith averages built from runs that never reported how long they took.- Correct
- Plain
dur_secs BETWEEN 0 AND 2700lets NULL durations evaluate to NULL and drop out, so only genuinely fast runs reach the average.
Common follow-up questions
- How would you flag pipelines whose average output is trending down over consecutive runs? (Tests a LAG window function to compare each run against the pipeline's prior run.)
- If the metric were rows per second instead of total rows, how would the query change? (Tests whether the candidate computes a true rate (`rows_out` / `dur_secs`) and guards the divisor with NULLIF.)
- What if some pipelines legitimately process zero rows on a given run? (Tests judgment about including or excluding zero-output runs and what that does to the ranking.)