Google-style Company ChallengeMediumVerified answerSQLite live

Video Views Per Category

How many total video views has each YouTube content category received?

  • Joins
  • Aggregation
  • Sorting

Challenge brief

Understand the request

Video Content Strategy is reviewing content category performance to guide recommendation algorithm tuning.

Return category, views in the declared deterministic order.

Return

  • category
  • views

Constraints

  • Count view records for every represented video category
  • Order by view count descending, then category

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

video_views

  • view_idINTEGER
  • user_idINTEGER
  • video_idINTEGER
  • view_dateDATE
  • watch_timeINTEGER

videos

  • video_idINTEGER
  • titleVARCHAR(200)
  • categoryVARCHAR(50)

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Video category comes from the catalog while view facts contain the counted events.

Hint 2

Connect the tables at video grain before grouping by category.

Hint 3

Order category totals using both the metric and label.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT v.category, COUNT(*) AS views FROM video_views vv INNER JOIN videos v ON vv.video_id = v.video_id GROUP BY v.category ORDER BY views DESC, v.category

Why this works

Each row in video_views is one view event. After joining to videos for the category label, COUNT(*) per category gives total views. Education has 15 views because the dataset contains many Education videos (Python tutorial, ML basics, etc.) that attract multiple viewers.

Success check

Returns the complete deterministic result for video views per category

Expected result

Use this output to verify values, aliases, ordering, and row count.

categoryviews
Education15
Finance4
Food4
Technology4
Travel4
Gaming3
Entertainment2
Health2

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.