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
| 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 | success_count |
|---|---|
| ml_train | 4 |
| import_csv | 4 |
| etl_users | 4 |
| sync_crm | 2 |
| export_s3 | 2 |
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
SELECT pipe_name, COUNT(*) AS success_count
FROM data_pipes
WHERE status = 'success'
GROUP BY pipe_name
ORDER BY success_count DESCSELECT pipe_name, COUNT(*) AS success_count
FROM data_pipes
GROUP BY pipe_name
ORDER BY success_count DESCSame shape, no WHERE: every failed, running, queued and skipped run is counted as a success.
Common follow-up questions
- If `pipe_name` contains trailing whitespace in some rows, how would that affect your `GROUP BY` result? (Dirty keys create phantom groups; grouping on `TRIM(pipe_name)` collapses them.)
- Should you filter with `WHERE status = 'success'` or count conditionally with `COUNT(CASE WHEN status = 'success' THEN 1 END)`? (The `WHERE` cuts rows before grouping. The conditional count reads every row and also keeps zero-success pipelines, which changes the answer.)
- How would you also display each pipeline's average `rows_out` alongside its success count? (Add `AVG(rows_out)` to the same select; it averages successful runs only.)