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

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 57 rows
monthunique_deployments
2022-012
2022-022
2022-031
2026-019
2026-028

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

Composite DISTINCT for unique deployment identity
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 month

Common follow-up questions