Successful Pipeline Runs

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
Spotify

Problem

In data_pipes, which logs every pipeline execution, a run counts as successful only when its status is exactly the lowercase 'success'; any other capitalization of that word is not a completed run. List each pipeline with at least one such run alongside its number of successful runs, most successes first.

Which pipelines completed successfully?

Tables

data_pipes

Columns: pipe_id INTEGER, pipe_name TEXT, status TEXT, rows_in INTEGER, rows_out INTEGER, start_at TIMESTAMP, 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 10 rows
pipe_namesuccess_count
ml_train4
import_csv4
etl_users4
sync_crm2
export_s32

Worked solution and explanation

What this really is

This is a filtered count presented as a pipeline report. Successful runs are a subset of data_pipes, and on this data status carries 7 spellings, with 'Success' sitting right beside 'success'. Anyone can write GROUP BY pipe_name. What separates candidates is filtering to exactly 'success' before counting. Drop the WHERE and every pipeline's number becomes its total executions under a success label; fold case with LOWER(status) and the 'Success' rows leak in. Pipelines fail at different rates, so the success_count ordering reshuffles as well.


Build it in order

Step 1: Narrow data_pipes to successful runs

Start with WHERE status = 'success'. Equality on text is case-sensitive, which is exactly what the statement asks for: 'Success' and 'FAILED' are other values and stay out. The filter runs before grouping, so the count only ever sees rows that belong in the answer.

Step 2: Group by pipe_name and count

pipe_id is unique per run, so grouping on it gives one row per execution. pipe_name is the pipeline. COUNT(*) counts the surviving rows, which are the successful runs. A pipeline with no success never forms a group, so there is no zero to back-fill.

Step 3: Alias it and sort descending

Name the count success_count and sort with ORDER BY success_count DESC. Order is graded, and a bare ORDER BY success_count sorts ascending. 3 pipelines tie at 4 here, and tied rows may come in any order.

The solution

Filter to 'success', then group and count
SELECT pipe_name, COUNT(*) AS success_count
FROM data_pipes
WHERE status = 'success'
GROUP BY pipe_name
ORDER BY success_count DESC
The trap: counting runs, not successes
SELECT pipe_name, COUNT(*) AS success_count
FROM data_pipes
GROUP BY pipe_name
ORDER BY success_count DESC

Same shape, no WHERE: every failed, running, queued and skipped run is counted as a success.


Common follow-up questions