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

deploy_logs: 10 of 200 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
131payment-apiv1.0.2stagingfailed2026-02-02 01:11:0023bob
162user-svcv1.1.0devrolled_back2026-03-03 02:22:0036charlie
193search-api2.0.0canaryin_progress2026-04-04 03:33:0049dana
224gatewayv2.1.0ProductionSuccess2026-05-05 04:44:0062eve
255notif-svc2.1.1STAGINGFAILED2026-06-06 05:55:0075frank
286analyticsv3.0.0-rc1productionsuccess2026-07-07 06:06:0088Alice
317ml-servingv1.0.3stagingfailed2026-08-08 07:17:00NULLBOB
348auth-svcv1.0.1devRolled_Back2026-09-09 08:28:00114alice
379Payment-APIv1.0.2canaryin_progress2026-01-10 09:39:00127bob
410user-svcv1.1.0ProductionSuccess2026-02-11 10:50:00140charlie

Expected output

First 5 of 7 rows
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

Services blocked from sign-off, one row each
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