# Thirty Days of Shipping

> A month in the life of an engineering team, counted one deploy at a time.

Canonical URL: <https://datadriven.io/problems/monthly_deployment_count>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

For each month, count unique deployments where a deployment is identified by the combination of service name and version. Format months as 'YYYY-MM'. Return the month and the unique deployment count.

## 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**

```sql
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
```

> **Cost Analysis**
>
> The query scans 500K rows from `deploy_logs`.

> **Interviewers Watch For**
>
> Naming the output grain ("one row per X") before writing the GROUP BY shows you think about data shape, not just syntax. Explaining why `ROW_NUMBER` is preferred over `DISTINCT` for deduplication shows you understand the difference between collapsing and selecting.

> **Common Pitfall**
>
> Comparing dates stored as TEXT without casting can produce lexicographic instead of chronological ordering. Always confirm the column type.

---

## Common 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.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/monthly_deployment_count)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.