Quiet Failures
A medium SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.
- Domain
- SQL
- Difficulty
- medium
- Seniority
- mid
- Asked in
- Wells Fargo
Problem
A payments platform's release team is auditing how reliably each service ships, and the deploy log records a successful outcome inconsistently as both 'Success' and 'success'. For each service with at least 15 deployments this year, report its total deployments, how many succeeded, and the resulting success rate, least reliable first.
Some services land every release; others only look like they do. Find the ones production can't count on.
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
| svc_name | deploy_count | success_count | success_pct |
|---|---|---|---|
| ml-serving | 15 | 0 | 0 |
| notif-svc | 15 | 0 | 0 |
| search-api | 15 | 0 | 0 |
| user-svc | 16 | 10 | 62.5 |
| gateway | 16 | 11 | 68.8 |
Worked solution and explanation
What this problem is really testing
Strip the costume and this is a per-service success rate riding on a dirty status column. Anyone can write a group-by with a ratio. The real test is whether you notice that 'Success' and 'success' are the same outcome written two ways, so a case-sensitive status = 'success' silently drops every capitalized win from your numerator. The query still runs and still prints tidy percentages, but every service that logged mixed casing now reads as far less reliable than it truly is. Get it wrong and gateway looks like a coin flip when it actually ships eleven of sixteen.
Break down the requirements
Step 1: Scope to this year's deployments
WHERE deploy_at >= '2026-01-01' limits the audit to the current year. Leave it out and you fold in four prior years of history, inflating every deploy_count and washing out the recent reliability picture the team asked for.
Step 2: Count successes case-insensitively
SUM(CASE WHEN LOWER(status) = 'success' THEN 1 ELSE 0 END) is the numerator. Compare status = 'success' instead and you skip every 'Success' row, so the count lands low and the rate droops below the truth. Normalize the casing inside the CASE, exactly once, and both the count and the rate come out right.
Step 3: Turn the counts into a rate and drop thin cohorts
100.0 * success_count / COUNT(*) forces float division so you do not floor the percentage to an integer 0. HAVING COUNT(*) >= 15 keeps a service with only a handful of deploys this year from landing at a noisy 0 or 100 percent and hijacking the ranking.
Step 4: List the least reliable first
ORDER BY success_pct ASC surfaces the shakiest services at the top. svc_name is the tie-break, so the four services sitting at 0.0 percent come out in a stable alphabetical order instead of whatever the engine happens to return.
The solution
SELECT
svc_name,
COUNT(*) AS deploy_count,
SUM(CASE WHEN LOWER(status) = 'success' THEN 1 ELSE 0 END) AS success_count,
ROUND(100.0 * SUM(CASE WHEN LOWER(status) = 'success' THEN 1 ELSE 0 END) / COUNT(*), 1) AS success_pct
FROM deploy_logs
WHERE deploy_at >= '2026-01-01'
GROUP BY svc_name
HAVING COUNT(*) >= 15
ORDER BY success_pct ASC, svc_nameCommon follow-up questions
- The team now wants `rolled_back` deploys treated as outright failures and `in_progress` ones excluded entirely. Which part of the query changes, and does your denominator move? (Tests whether they separate the success predicate in the numerator from the population filter in the WHERE.)
- How would you keep this incremental over just the last 30 days on a 40M row table? (Probes partition pruning on `deploy_at` and why the LOWER(status) predicate must not block it.)
- A service shows 100 percent over 15 deploys while another shows 98 percent over 500. How would you rank so the small sample does not read as more reliable? (Pushes toward volume-weighting or a lower-bound confidence interval rather than a raw rate.)