Busiest Pipeline Month

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
ESPN

Problem

Each row of data_pipes is one pipeline execution with its start_at timestamp and, when the run's duration was captured, its dur_secs. With every year pooled together, which calendar month had the most executions with a captured duration, and how many did it have?

One month, more pipeline runs than any other.

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 1 of 1 rows
monthpipeline_runs
0217

Worked solution and explanation

What this really is

This is a month-of-year tally with one quiet filter, and the filter is where candidates split. Anyone can pull the month out of start_at and count rows. The real question is which column you guard. start_at is filled on every row of data_pipes, while dur_secs is missing on 40 of the 200 runs. Count every row and February comes back with 22. Count only the runs with a captured duration and it is 17. The month is the same but the number is wrong, and the grade compares the number.

Step 1: Read the grain off the preview

The preview shows '02', not '2026-02'. That means month of the year with every year pooled, so STRFTIME('%m', start_at) is the key. If you reach for '%Y-%m', February of one year lands in a different bucket from February of the next, and you have answered a question nobody asked.

Step 2: Drop the untimed runs before counting

Only runs whose duration was captured count, so WHERE dur_secs IS NOT NULL runs first and those rows never reach a bucket. Put the guard on dur_secs, the column that actually has gaps. start_at has none on this table.

Step 3: Count executions, not pipelines

Each row is one execution, so the metric is COUNT(*) per month. COUNT(DISTINCT pipe_name) collapses to at most 10 per month, because there are only ten pipelines. SUM(rows_in) measures data volume, not runs.

Step 4: Keep only the busiest month

ORDER BY pipeline_runs DESC LIMIT 1 keeps the top bucket. On this data February leads at 17 and the next months sit at 16, so the cut never falls inside a tie.

The solution

Busiest calendar month by timed runs
SELECT
    STRFTIME('%m', start_at) AS month,
    COUNT(*) AS pipeline_runs
FROM data_pipes
WHERE dur_secs IS NOT NULL
GROUP BY STRFTIME('%m', start_at)
ORDER BY pipeline_runs DESC
LIMIT 1

Only runs with a captured dur_secs are counted, every year pooled into its calendar month.

Count every row
With no filter, COUNT(*) puts February at 22. The 5 February runs with no dur_secs are counted as if they happened like the rest.
Count timed runs
With WHERE dur_secs IS NOT NULL, those 5 rows are gone before the grouping and February reports 17, which is the number the grade expects.

Common follow-up questions