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_items: 10 of 200 rows
content_idtitlecontent_typeduration_secondscreator_idpublish_date
243The Ultimate Guide to AI TrendsarticleNULL1972026-02-02
286Top 10 Mobile Appspodcast1542942025-03-03
329Understanding Machine Learning [DRAFT]short2013912026-04-04
372Mastering Tech Startupslivestream2484882025-05-05
415Introduction to Cybersecurityvideo2955852026-06-06
458Deep Dive: Cloud ComputingarticleNULL6822025-07-07
501Behind the Scenes of Product Managementpodcast3897792026-08-08
544Breaking Down DevOpsshort4368762025-09-09
587Exploring Web Developmentlivestream483NULL2026-01-10
630How to Data Sciencevideo53010702025-11-11

Expected output

First 5 of 38 rows
creator_idavg_duration
44654525
27193679
1003585
47563491
46593444

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

HIGH OUTPUT CREATORS
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 DESC

COMMON FOLLOW-UP QUESTIONS

Common follow-up questions