Year-over-Year Content Launches

A medium SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
medium
Seniority
L3
Asked in
Tesla

Problem

A content analyst noticed the year-over-year output figures for the platform's video side are inflated by articles and podcasts. Rebuild them from content_items counting only video, short and livestream items: every creator who has ever published one gets a line with their 2026 count minus their 2025 count. Items with no creator on record stay together as one uncredited line.

Launch velocity, year over year.

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 31 rows
creator_idnet_difference
NULL-2
1000
3912
488-2
5854

Worked solution and explanation

Two filters that look alike

This is a pivot of two years into one signed number, dressed up as a report cleanup. Anyone can write the two conditional sums. What separates candidates is where each restriction goes: the format rule belongs in WHERE because it decides which items exist, while the years belong inside the CASE because they only decide which side of the subtraction an item lands on. Push the years into WHERE and every creator whose video output sat in earlier years vanishes instead of showing a flat zero.

Step 1: Throw out the non-video items first

WHERE content_type IN ('video', 'short', 'livestream') removes articles and podcasts before anything is counted. That is the whole reason the old figures were wrong, so it is a row filter, applied once.

Step 2: Bucket each item by year inside the sum

SUM(CASE WHEN STRFTIME('%Y', publish_date) = '2026' THEN 1 ELSE 0 END) counts this year's items; the twin with '2025' counts last year's. Items from other years add 0 to both, which is exactly what lets a flat creator stay on the list.

Step 3: Subtract in one pass per creator

GROUP BY creator_id and subtract the two sums. No join, no second scan, and the NULL creator falls out as its own group: that is the uncredited line.

Video-only year-over-year delta
SELECT
    creator_id,
    SUM(CASE WHEN STRFTIME('%Y', publish_date) = '2026' THEN 1 ELSE 0 END)
    - SUM(CASE WHEN STRFTIME('%Y', publish_date) = '2025' THEN 1 ELSE 0 END) AS net_difference
FROM content_items
WHERE content_type IN ('video', 'short', 'livestream')
GROUP BY creator_id
The tidy-looking version that loses creators
SELECT
    creator_id,
    SUM(CASE WHEN STRFTIME('%Y', publish_date) = '2026' THEN 1 ELSE 0 END)
    - SUM(CASE WHEN STRFTIME('%Y', publish_date) = '2025' THEN 1 ELSE 0 END) AS net_difference
FROM content_items
WHERE content_type IN ('video', 'short', 'livestream')
  AND STRFTIME('%Y', publish_date) IN ('2025', '2026')
GROUP BY creator_id

Years in WHERE drop every video creator with nothing in the two years.

Row filter
content_type IN (...) in WHERE: decides whether an item counts at all.
Bucket condition
The year test inside CASE: decides which count an item feeds, never whether its creator appears.

Common follow-up questions