Thirty Days of Shipping
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
- Zest AI
Problem
A platform engineering team tracks how many separate deployments ship each month, where a deployment is a unique pairing of service and version. Walk the timeline from the earliest month onward, showing each month as 'YYYY-MM' next to its count of unique deployments.
A month in the life of an engineering team, counted one deploy at a time.
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
| month | unique_deployments |
|---|---|
| 2022-01 | 2 |
| 2022-02 | 2 |
| 2022-03 | 1 |
| 2026-01 | 9 |
| 2026-02 | 8 |
Worked solution and explanation
Why this problem exists in real interviews
Querying deploy_logs for svc_name data using grouping and date extraction tests whether you can translate a business requirement into the right column references and filter sequence. It shows up as a fundamentals check to verify practical fluency.
Break down the requirements
Step 1: Aggregate with COUNT DISTINCT
Group by the output grain and apply COUNT DISTINCT() to compute the metric. The GROUP BY must match exactly what the output needs: one row per group key.
Step 2: Order the final output
Apply ORDER BY as specified to produce the expected row sequence. When tied values exist, add a secondary sort column for determinism.
The solution
SELECT STRFTIME('%Y-%m', deploy_at) AS month,
COUNT(DISTINCT svc_name || ':' || version) AS unique_deployments
FROM deploy_logs
GROUP BY STRFTIME('%Y-%m', deploy_at)
ORDER BY monthCommon follow-up questions
- What happens to your result if `deploy_logs`.dur_secs contains NULLs for some rows? (Tests whether the candidate accounts for NULL behavior in aggregates and comparisons on `dur_secs`.)
- How would you verify that your aggregation on `deploy_logs`.log_id is not double-counting due to duplicate rows? (Tests data quality awareness and deduplication strategies.)
- With millions of distinct values in `deploy_logs`.log_id, what index strategy would you use to keep this query performant? (Tests indexing knowledge specific to high-cardinality columns like `log_id`.)