# Lowest Average Price Category

> The cheapest category. Not necessarily the worst.

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

The pricing team wants to identify the most budget-friendly segment of the catalog. Which product category has the lowest average price?

## Worked solution and explanation

### Why this problem exists in real interviews

Against the products table, grouping and top-N selection on product_name values is the key operation. Interviewers favor this as a fundamentals check because it exposes whether candidates handle ties, NULLs, and ordering edge cases correctly.

---

### Break down the requirements

#### Step 1: Aggregate with AVG

Group by the output grain and apply `AVG()` to compute the metric. The `GROUP BY` must match exactly what the output needs: one row per group key.

#### Step 2: Order and limit the output

Sort by the target metric and apply `LIMIT` to return the requested number of rows. Ensure the sort is deterministic to produce reproducible results.

---

### The solution

**Ascending aggregate for minimum average**

```sql
SELECT category, AVG(price) AS avg_price
FROM products
GROUP BY category
ORDER BY avg_price ASC
LIMIT 1
```

> **Cost Analysis**
>
> The query scans 15K rows from `products`.

> **Interviewers Watch For**
>
> Naming the output grain ("one row per X") before writing the GROUP BY shows you think about data shape, not just syntax.

> **Common Pitfall**
>
> Returning more columns than the prompt asks for can trigger a "wrong schema" failure in automated grading. Match the output specification exactly.

---

## Common follow-up questions

- What happens to your result if products.rating contains NULLs for some rows? _(Tests whether the candidate accounts for NULL behavior in aggregates and comparisons on rating.)_
- How would you verify that your aggregation on products.product_id is not double-counting due to duplicate rows? _(Tests data quality awareness and deduplication strategies.)_
- What index would you add to products to avoid a full table scan when filtering or sorting by product_id? _(Tests practical indexing decisions for numeric filter columns.)_

## Related

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