High-Output Creators
An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.
- Domain
- SQL
- Difficulty
- easy
- Seniority
- L4
- Asked in
- Airbnb
Problem
Which creators have published at least an hour of content in total (3,600 seconds), and what is each one's average duration per item, from the longest average down to the shortest? Items with no creator on record pool together as a single unattributed entry that is held to the same hour bar.
High engagement creators.
Tables
content_items
Columns: content_id INTEGER, title TEXT, content_type TEXT, duration_seconds INTEGER, creator_id INTEGER, publish_date TEXT
| content_id | title | content_type | duration_seconds | creator_id | publish_date |
|---|---|---|---|---|---|
| 243 | The Ultimate Guide to AI Trends | article | NULL | 197 | 2026-02-02 |
| 286 | Top 10 Mobile Apps | podcast | 154 | 294 | 2025-03-03 |
| 329 | Understanding Machine Learning [DRAFT] | short | 201 | 391 | 2026-04-04 |
| 372 | Mastering Tech Startups | livestream | 248 | 488 | 2025-05-05 |
| 415 | Introduction to Cybersecurity | video | 295 | 585 | 2026-06-06 |
| 458 | Deep Dive: Cloud Computing | article | NULL | 682 | 2025-07-07 |
| 501 | Behind the Scenes of Product Management | podcast | 389 | 779 | 2026-08-08 |
| 544 | Breaking Down DevOps | short | 436 | 876 | 2025-09-09 |
| 587 | Exploring Web Development | livestream | 483 | NULL | 2026-01-10 |
| 630 | How to Data Science | video | 530 | 1070 | 2025-11-11 |
Expected output
| creator_id | avg_duration |
|---|---|
| 4465 | 4525 |
| 2719 | 3679 |
| 100 | 3585 |
| 4756 | 3491 |
| 4659 | 3444 |
Worked solution and explanation
Why this problem exists in real interviews
Two aggregates over the same group, used for different purposes: SUM gates who qualifies (an hour of total runtime) and AVG shapes the output and the sort. Mixing the two up, filtering on AVG or thresholding each item in WHERE, is the failure mode. The HAVING clause is the natural home for the gate.
Break down the requirements
Step 1: Group by creator_id
Every metric lives at the creator grain. GROUP BY creator_id is the only sensible key because content_items is one row per piece of content, not per creator. Rows with a NULL creator_id fall into one group of their own, which is exactly the unattributed entry the question asks for.
Step 2: Gate on total runtime, not per-item
HAVING SUM(duration_seconds) >= 3600 filters the groups. Putting the threshold in WHERE would filter individual items, which is not what an hour of total content means.
Step 3: Project the average and sort
AVG(duration_seconds) is independent of the gate. ORDER BY avg_duration DESC puts the long-form creators at the top, which is what an editorial team would scan first. Creators tied on the average can come in either order.
The solution
SELECT creator_id,
AVG(duration_seconds) AS avg_duration
FROM content_items
GROUP BY creator_id
HAVING SUM(duration_seconds) >= 3600
ORDER BY avg_duration DESCCOMMON FOLLOW-UP QUESTIONS
Common follow-up questions
- Restrict this to creators whose first publish was in the last 12 months. (Tests whether you add a `MIN(publish_date)` condition to `HAVING` or filter inside a subquery.)
- Return the median duration per creator instead of the average. (Probes knowledge of `PERCENTILE_CONT` or `PERCENTILE_DISC` and how engines differ on syntax.)
- Now break the average out by `content_type` within each qualifying creator. (Checks comfort with multi-key grouping and whether the hour threshold stays at the creator level or moves to the type level.)