Prolific Authors in Largest Service Teams
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
- L4
- Asked in
- Zenefits
Problem
List the stable versions shipped by whoever has deployed the most different versions in deploy_logs. Release candidates still count toward being the most prolific but stay out of the release team's digest, and the log's casing is unreliable, so 'BOB' and 'bob' are the same person.
Senior leads in the biggest teams.
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
| author | version |
|---|---|
| bob | v1.0.2 |
| bob | v1.0.3 |
| alice | v1.0.1 |
Worked solution and explanation
What this problem really is
Under the release-digest costume this is a max-of-aggregates filter on a dirty key: count each person's different versions, find the top count, keep everyone sitting at it, then print their stable releases. The release-candidate filter is the easy part. What separates candidates is deciding who a person is before counting anything. The log signs one deployer 'bob' on one service and 'BOB' on another, so a raw count credits each spelling with a single version, everybody ties at one, and the digest names the whole team instead of the two people who actually ship the most.
Building it up
Step 1: Decide who a person is
Group on LOWER(author), never on author. 'bob' and 'BOB' each shipped one version; together they shipped two, and that is the whole difference between a leader and a tie with everyone.
Step 2: Count versions, not deploys
COUNT(DISTINCT version) per person measures how many releases they put out. Each version is deployed again and again across environments, so the distinct count is what keeps a redeploy from looking like new work.
Step 3: Find the top count
Wrap the per-person counts in the derived table shipped_counts and take MAX(versions_shipped). It runs over a handful of people, not the deploy rows, and returns the single bar everyone is measured against.
Step 4: Keep everyone at the top
Inside the IN subquery, HAVING COUNT(DISTINCT version) = (SELECT MAX(versions_shipped) ...) keeps exactly the people at the top. The outer LOWER(author) IN (...) then matches every spelling of those people back to their rows.
Step 5: Print the stable releases
Only now apply version NOT LIKE '%-rc%', and select LOWER(author) with version under DISTINCT. The filter lives in the outer query because release candidates still counted toward who leads; they just do not get printed.
The solution
SELECT DISTINCT LOWER(author) AS author, version
FROM deploy_logs
WHERE version NOT LIKE '%-rc%'
AND LOWER(author) IN (
SELECT LOWER(author)
FROM deploy_logs
GROUP BY LOWER(author)
HAVING COUNT(DISTINCT version) = (
SELECT MAX(versions_shipped)
FROM (
SELECT COUNT(DISTINCT version) AS versions_shipped
FROM deploy_logs
GROUP BY LOWER(author)
) AS shipped_counts
)
)- Filter, then count
- Putting
version NOT LIKE '%-rc%'in every subquery removes the release candidate from the ranking too. A leader whose second version was a candidate drops to one, and their stable release disappears from the digest without an error. - Count, then filter
- The ranking reads every version; only the outer
WHEREdrops candidates. Both leaders stay at the top, and the digest lists only what actually shipped stable.
Common follow-up questions
- If the digest could credit only one person, how would you choose among tied leaders deterministically? (Tests replacing the tie-keeping match with a deterministic pick.)
- Could a window function over the per-person counts find the leaders, and would it scan `deploy_logs` fewer times? (Probes window-function fluency as an alternative to the nested scalar subquery.)
- `svc_name` also has casing and padding variants. If the question became services per person, what would you normalize? (Tests whether the candidate spots the other dirty columns.)