The Green Light
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
- ESPN
Problem
Two things keep a service off our release sign-off: a deploy in deploy_logs still marked in progress, or one marked successful that never recorded how long it took. List every blocked service once, however its name happens to be typed in the log.
Success hides behind a dozen spellings. Find who actually shipped.
Tables
deploy_logs
Columns: log_id INTEGER, svc_name TEXT, version TEXT, env_name TEXT, status TEXT, deploy_at TEXT, dur_secs INTEGER, author TEXT
| log_id | svc_name | version | env_name | status | deploy_at | dur_secs | author |
|---|---|---|---|---|---|---|---|
| 131 | payment-api | v1.0.2 | staging | failed | 2026-02-02 01:11:00 | 23 | bob |
| 162 | user-svc | v1.1.0 | dev | rolled_back | 2026-03-03 02:22:00 | 36 | charlie |
| 193 | search-api | 2.0.0 | canary | in_progress | 2026-04-04 03:33:00 | 49 | dana |
| 224 | gateway | v2.1.0 | Production | Success | 2026-05-05 04:44:00 | 62 | eve |
| 255 | notif-svc | 2.1.1 | STAGING | FAILED | 2026-06-06 05:55:00 | 75 | frank |
| 286 | analytics | v3.0.0-rc1 | production | success | 2026-07-07 06:06:00 | 88 | Alice |
| 317 | ml-serving | v1.0.3 | staging | failed | 2026-08-08 07:17:00 | NULL | BOB |
| 348 | auth-svc | v1.0.1 | dev | Rolled_Back | 2026-09-09 08:28:00 | 114 | alice |
| 379 | Payment-API | v1.0.2 | canary | in_progress | 2026-01-10 09:39:00 | 127 | bob |
| 410 | user-svc | v1.1.0 | Production | Success | 2026-02-11 10:50:00 | 140 | charlie |
Expected output
| service |
|---|
| analytics |
| gateway |
| ml-serving |
| notif-svc |
| payment-api |
Worked solution and explanation
What this problem really is
Strip the release costume and this is a dirty-key cleanup wearing a two-rule filter. The rules read easily: a deploy still 'in_progress' blocks its service outright, and a success blocks it only when dur_secs was never recorded. What separates candidates is noticing that both the label and the key lie. Success is spelled 'success', 'Success' and 'SUCCESS', and analytics qualifies only through a 'Success' row, so an exact match quietly drops it. The in-progress payment-api deploys were typed as 'Payment-API' and 'payment-api ' as well as 'payment-api'. Group on the raw svc_name and the same service comes back three times.
Build it up
Step 1: Write the two blocking rules
A deploy blocks sign-off if status = 'in_progress', or if it succeeded and dur_secs IS NULL. The missing-duration test belongs to the success rule only: an in-progress deploy blocks whether or not it has logged a duration. Parenthesize the success half so a reader sees which conditions travel together.
Step 2: Fold the status casing
'in_progress' has one spelling in this log, but success has three. Compare on LOWER(status) = 'success' so 'Success' and 'SUCCESS' count. That is the only path by which analytics makes the list.
Step 3: Test for a missing duration, not a zero
A duration that was never recorded is NULL. dur_secs = 0 would match a real instant rollout, and dur_secs = NULL matches nothing, so the test is dur_secs IS NULL.
Step 4: Normalize the service name before collapsing
Group on LOWER(TRIM(svc_name)) and return that same expression as service. TRIM alone leaves 'Payment-API' as its own service, and LOWER alone leaves the trailing-space 'payment-api ' as one. Together they give one row per real service.
The solution
SELECT LOWER(TRIM(svc_name)) AS service
FROM deploy_logs
WHERE status = 'in_progress'
OR (LOWER(status) = 'success' AND dur_secs IS NULL)
GROUP BY LOWER(TRIM(svc_name))Common follow-up questions
- If a stuck deploy recorded `dur_secs = 0` instead of leaving it `NULL`, would your filter still find it? (Tests whether they separate a missing metric from a real zero.)
- If sign-off should only consider each service's latest deploy, how would you pick that row per service before applying the rules? (Tests moving from any-row logic to a per-key latest record.)
- Could you get the same list with `SELECT DISTINCT` instead of `GROUP BY`? When would you prefer one over the other? (Tests knowledge of alternatives for deduplication.)
- If this check ran every hour, would you keep normalizing `svc_name` and `status` at query time or clean them on write? (Tests where data cleaning belongs in a pipeline.)