The Weight of a Verdict

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
Zenefits

Problem

Each pipeline run in data_pipes gets benchmarked by the data platform team against every run sharing its status, using the total rows ingested across that status (a status whose runs never recorded an ingest count has no benchmark). Return every run with its original columns intact, alongside that status-wide total.

Every run carries the full measure of all who ended the same way.

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 200 rows
pipe_idpipe_namestatusrows_inrows_outstart_atdur_secsstatus_total_rows_in
286export_s3FAILED8225822026-07-07 06:00:00143197554
503sync_crmFAILED178112612026-05-14 13:00:00304197554
255agg_weeklySuccess6854852026-06-06 05:00:00NULL193718
131etl_usersfailed137972026-02-02 01:00:0028205500
193sync_crmqueued4112912026-04-04 03:00:0074186046

Worked solution and explanation

What this really tests

This is grain preservation dressed up as benchmarking. Totalling rows_in per status is the easy half. The real skill is attaching that total to every run without letting the status collapse the runs. Aggregate the table outright and 200 runs fold into seven status rows: the numbers are right, and every column the team asked to keep is gone.

Build it

Step 1: Read the grain off the ask

'Return every run with its original columns intact' fixes the output at one row per run. The benchmark belongs to the group, but it is reported at the run's grain, so it rides along as one extra column.

Step 2: Total rows_in over the run's whole status

SUM(rows_in) OVER (PARTITION BY status) adds up every run sharing the current row's status and writes that sum onto each of them. There is no ORDER BY inside the window, so the frame is the entire status, not a running prefix.

Step 3: Take status exactly as stored

The seed spells some statuses two ways, and each spelling is its own status: the preview shows 'FAILED' at 197554 and 'failed' at 205500. Partitioning on the raw value is what the grader expects.

Step 4: Let missing ingest counts fall out

SUM skips NULLs, so the 28 runs without a rows_in add nothing. Every one of them is a 'success' run, which leaves 'success' with no recorded counts at all: its benchmark comes back NULL, while 'Success' gets a real total. That is the empty benchmark the statement describes, not a bug.

Status total attached to every run
SELECT
    pipe_id,
    pipe_name,
    status,
    rows_in,
    rows_out,
    start_at,
    dur_secs,
    SUM(rows_in) OVER (PARTITION BY status) AS status_total_rows_in
FROM data_pipes

Common follow-up questions