The Legacy Hunt

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

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
Google

Problem

The platform team is retiring the legacy scheduler and needs its run calendar from before the May 1, 2026 migration. List every calendar day on which at least one pipeline started a run.

Old data. Still matters.

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 126 rows
run_date
2026-02-02
2026-03-03
2026-04-04
2026-01-10
2026-02-11

Worked solution and explanation

What this really is

Under the sunset framing this is a plain set-reduction: turn a one-row-per-run log into the set of calendar days that had activity, cut off at the migration date. Anyone can filter by date. What separates candidates is seeing that data_pipes stores one row per RUN, not per day, so a bare SELECT DATE(start_at) hands back the same day dozens of times, and that start_at is a TIMESTAMP: use <= against '2026-05-01' and every run at midnight on migration day leaks into a calendar that is supposed to end before it.


The two moves

Step 1: Collapse runs into days

Each row is a single run, and a busy pipeline fires many times a day. DATE(start_at) throws away the clock time so runs at 02:00 and 22:00 on the same day become one value, and DISTINCT keeps a single copy of each day. Skip it and the audit team gets tens of thousands of rows where they expected a tidy calendar.

Step 2: Cut strictly before the cutoff

start_at is a TIMESTAMP and the migration boundary is the date '2026-05-01'. Strict less-than keeps every run through the last instant of April 30 and drops the first instant of May 1 onward. <= '2026-05-01' would let midnight on migration day slip in; <= '2026-04-30' would silently drop all of April 30's runs. Strict-less-than against the start of the day after the window is the bug-free pattern.

The solution

Dedup to days, cut on a strict boundary
SELECT DISTINCT DATE(start_at) AS run_date
FROM data_pipes
WHERE start_at < '2026-05-01';

Common follow-up questions