# Binary Flag Indicators

> On or off. Every flag at a glance.

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

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

The feature flag dashboard needs a clean boolean representation for downstream consumers. For each flag, show the flag name, a 1/0 indicator for whether it is enabled, and a 1/0 indicator for whether it is disabled.

## Worked solution and explanation

### Why this problem exists in real interviews

The core skill being tested is grouped aggregation over `feat_flags`. Candidates must decide how `flag_name`, `enabled`, `rollout` interact before choosing a join strategy or aggregation level.

---

### Break down the requirements

#### Step 1: Group by `flag_name`

`GROUP BY` at the correct grain produces one row per group.

#### Step 2: Compute `COUNT(*)`

The COUNT function counts rows per group.

#### Step 3: Order by the metric

Sort by `cnt` desc for readability.

---

### The solution

**Group-aggregate for binary flag indicators**

```sql
SELECT
    flag_name,
    COUNT(*) AS cnt
FROM feat_flags
GROUP BY flag_name
ORDER BY cnt DESC
```

> **Cost Analysis**
>
> The main table has 500 rows. The GROUP BY reduces the row count early, keeping downstream operations cheap.

> **Interviewers Watch For**
>
> Strong candidates state the correct `GROUP BY` grain before writing any SQL, showing they think about the output shape first.

> **Common Pitfall**
>
> Selecting a non-aggregated column without including it in `GROUP BY` is the most common error. Some engines reject it; others silently return arbitrary values.

---

## Common follow-up questions

- What happens to your results if `flag_name` in `feat_flags` contains trailing whitespace or mixed casing? _(Tests awareness of text normalization issues that silently fragment GROUP BY results.)_
- Your GROUP BY aggregates `flag_id` from `feat_flags`. If two groups have the same aggregate value, how is the output ordered, and is that deterministic? _(Tests awareness that ORDER BY on a non-unique value produces non-deterministic row order without a tiebreaker.)_
- The `enabled` column in `feat_flags` has a zipf distribution, meaning a few values dominate. How does that skew affect your query plan and parallelism? _(Tests understanding of data skew: the optimizer may choose a bad plan when histogram statistics are stale.)_
- If `flag_id` in `feat_flags` contained negative values, would your query still produce correct results? _(Tests whether the candidate validated assumptions about the domain of numeric columns.)_

## Related

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