# Disabled Flag Ratio

> Feature flags that went dark. What percentage fell silent?

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

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

An early rollout on January 2, 2022 disabled several feature flags at once. Among flags that were updated on that exact date, what fraction are disabled (enabled = 0)? Return a single decimal value.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests conditional aggregation with a date filter to produce a single scalar ratio. It probes whether you can compute a fraction of rows meeting a condition within a filtered subset.

---

### Break down the requirements

#### Step 1: Filter to flags updated on the target date

`WHERE updated::DATE = '2026-01-10'` restricts to the rollout date.

#### Step 2: Compute the disabled fraction

`SUM(CASE WHEN enabled = false THEN 1.0 ELSE 0 END) / COUNT(*)` gives the ratio.

---

### The solution

**Date-filtered conditional ratio**

```sql
SELECT
    ROUND(SUM(CASE WHEN enabled = false THEN 1.0 ELSE 0 END) / COUNT(*), 4) AS disabled_ratio
FROM feat_flags
WHERE updated::DATE = '2026-01-10'
```

> **Cost Analysis**
>
> Scan of 400 rows. Trivially fast. Single-row output.

> **Interviewers Watch For**
>
> Whether the candidate casts the numerator to a decimal (1.0 instead of 1) to avoid integer division. Without the cast, the result would be 0 or 1.

> **Common Pitfall**
>
> Integer division: `SUM(CASE WHEN ... THEN 1 ELSE 0 END) / COUNT(*)` returns 0 in PostgreSQL because both operands are integers. Use 1.0 in the THEN clause.

---

## Common follow-up questions

- What if no flags were updated on that date? _(COUNT(*) returns 0, causing division by zero. Use NULLIF.)_
- How would you express this as a percentage? _(Multiply by 100.)_
- What if the date column includes timezone information? _(Tests timezone-aware date casting: AT TIME ZONE or ::DATE behavior.)_

## Related

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