# Average High-Range Accuracy

> The top-scoring models. What's their average?

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

The ML team is deciding whether to retrain the highest-accuracy models or leave them alone. Accuracy is stored as a decimal between 0 and 1. Compute the average accuracy across all models whose accuracy, when expressed as a percentage, falls between 91 and 100 inclusive.

## Worked solution and explanation

### Why this problem exists in real interviews

The `ml_models` schema makes this a clean test of grouped aggregation. Columns like `mdl_name`, `version`, `accuracy` introduce enough ambiguity that only candidates who clarify assumptions produce correct results.

---

### Break down the requirements

#### Step 1: Group by `status`

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

#### Step 2: Compute `AVG(accuracy)`

The AVG function computes the avg per group.

#### Step 3: Order by the metric

Sort by `avg_accuracy` desc for readability.

---

### The solution

**Group-aggregate for average high-range accuracy**

```sql
SELECT
    status,
    AVG(accuracy) AS avg_accuracy
FROM ml_models
GROUP BY status
ORDER BY avg_accuracy DESC
```

> **Cost Analysis**
>
> The main table has 800 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

- The `accuracy` column in `ml_models` has roughly 2% NULLs. How does your query handle those rows, and would the result change if NULLs were replaced with zeros? _(Tests whether the candidate understands how NULLs propagate through aggregation functions and whether their WHERE/JOIN conditions implicitly filter them out.)_
- Your GROUP BY aggregates `model_id` from `ml_models`. 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 `mdl_name` column in `ml_models` 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.)_
- How would you modify this query to run incrementally as new rows arrive in `ml_models` each hour? _(Tests whether the candidate can think about incremental computation vs full recomputation.)_

## Related

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