# Satisfaction by Platform

> Satisfaction scores, platform by platform.

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

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

For users in the 25-34 age bucket, calculate the average experiment outcome for each platform, rounded to the nearest whole number.

## Worked solution and explanation

### Why this problem exists in real interviews

This challenge asks you to apply self-join to the `experiments` and `users` tables, simulating a real user behavior workflow. Pay attention to columns like `user_id`, `outcome`, and `platform` as they drive the aggregation and output.

---

### Break down the requirements

#### Step 1: Join `experiments` to `users`

The join connects the two tables on their shared key. This brings the columns needed for filtering and aggregation into a single row set.

#### Step 2: Select the target columns

The SELECT clause picks exactly the columns the prompt asks for. Returning extra columns or missing a required alias would fail the grading check.

---

### The solution

**Join `experiments` to `users` to find satisfaction by platform**

```sql
SELECT e.platform, CAST(ROUND(AVG(e.outcome)) AS DOUBLE) AS avg_satisfaction
FROM experiments e
INNER JOIN users u ON e.user_id = u.user_id
WHERE u.age_bucket = '25-34'
GROUP BY e.platform
```

> **Cost Analysis**
>
> With ~17M rows, the join cost depends on the smaller table's cardinality. An index on the filter/join columns would reduce the scan to a seek.

> **Interviewers Watch For**
>
> Interviewers watch for whether the query returns exactly the columns and ordering the prompt specifies; how quickly you identify the core operation and write clean, minimal code.

> **Common Pitfall**
>
> Integer division truncates the result silently. Cast at least one operand to DOUBLE before dividing to get a decimal result.

---

## Common follow-up questions

- If `outcome` in `experiments` is NULL for some rows, how would your aggregation or join logic be affected? _(Probes understanding of NULL propagation through joins and aggregate functions on `experiments.outcome`.)_
- With 15,000,000 distinct values in `users.user_id`, how would a composite index on the GROUP BY columns change the execution plan? _(Probes understanding of how cardinality in `user_id` affects grouping and sort operations.)_
- How would you modify this query if the business logic required grouping by both `exp_id` and `exp_name` instead of just one? _(Tests ability to adapt the query structure to changing requirements.)_

## Related

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