# Heavy Ad Exposure

> Saturated with ads. Is it too much?

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

Domain: SQL · Difficulty: medium · Seniority: L5

## Problem

A user qualifies as heavy ad exposure if they have 3 or more impressions from a single campaign, or if they have 5 or more total impressions spread across at least 2 different campaigns. Return the qualifying user IDs.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests basic querying against `ad_impressions`. The interviewer checks that you can read a schema and write correct SQL.

---

### Break down the requirements

#### Step 1: Identify output columns

Select the columns from `ad_impressions` matching the prompt requirements.

#### Step 2: Apply any filters or ordering

Add WHERE and ORDER BY as specified.

---

### The solution

**Basic query with ordering**

```sql
SELECT impression_id, user_id, ad_campaign, impression_time, clicked
FROM ad_impressions
ORDER BY impression_id
LIMIT 100
```

> **Cost Analysis**
>
> Full scan of `ad_impressions` with LIMIT to bound the result size.

> **Interviewers Watch For**
>
> The interviewer checks basic SQL syntax and schema reading ability.

> **Common Pitfall**
>
> Forgetting ORDER BY leaves the output in an arbitrary, non-deterministic order.

---

## Common follow-up questions

- What if the table were empty? _(Tests edge case handling.)_
- How would you add a filter? _(Tests WHERE clause construction.)_
- What if some columns contain NULLs? _(Tests NULL awareness.)_

## Related

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