# Higher Performing Variant

> Control versus treatment. One wins.

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

We ran an A/B test with control and treatment variants. Which variant produces a higher average metric value? Return only the winning variant with its average rounded to 2 decimal places.

## Worked solution and explanation

### Why this problem exists in real interviews

Filtering rows with WHERE tests basic query construction. The interviewer verifies fundamental SQL fluency.

---

### Break down the requirements

#### Step 1: Apply the filter

Construct the WHERE clause based on the prompt's criteria for `test_name`.

#### Step 2: Select and order

Return the columns specified, ordered meaningfully.

---

### The solution

**Filtered query with WHERE clause**

```sql
SELECT result_id, test_name, variant, user_id, metric
FROM ab_results
WHERE test_name IS NOT NULL
ORDER BY result_id
```

> **Cost Analysis**
>
> An index on `test_name` enables a fast range or equality scan.

> **Interviewers Watch For**
>
> Clean, readable WHERE clauses signal basic competence.

> **Common Pitfall**
>
> Mixing AND and OR without parentheses leads to unexpected results due to operator precedence.

---

## Common follow-up questions

- How would you add a date range filter? _(Tests BETWEEN or comparison operators.)_
- What if the filter column could be NULL? _(Tests IS NOT NULL handling.)_
- How would you parameterize this for an application? _(Tests parameterized query awareness.)_

## Related

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