# Deployments per Environment

> Dev, staging, prod. Where do most deploys land?

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

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

Staging has been overloaded lately and the team suspects it's getting more deploys than production. Show the deployment count for each environment so they can confirm.

## Worked solution and explanation

### Why this problem exists in real interviews

This is a basic GROUP BY with COUNT. It tests the simplest form of aggregation for comparing groups.

---

### Break down the requirements

#### Step 1: Group by environment

`GROUP BY env_name` with `COUNT(*)` for deployment count.

---

### The solution

**Simple environment count**

```sql
SELECT env_name, COUNT(*) AS deploy_count
FROM deploy_logs
GROUP BY env_name
```

> **Cost Analysis**
>
> Scan of 700K rows. Trivially fast. A handful of environments in the output.

> **Interviewers Watch For**
>
> Whether the candidate keeps the query minimal. No sorting or filtering is required by the prompt.

> **Common Pitfall**
>
> Adding ORDER BY or HAVING when not requested adds unnecessary complexity. Read the prompt for exact output requirements.

---

## Common follow-up questions

- How would you confirm whether staging has more deploys than production? _(Add ORDER BY deploy_count DESC or a WHERE filter.)_
- How would you show this as a percentage of total deploys? _(Tests 100.0 * COUNT(*) / SUM(COUNT(*)) OVER ().)_
- What if some deployments have NULL env_name? _(They form a NULL group. Tests whether to exclude or label them.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/deployments_per_environment)
- [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.