Netflix-style Company ChallengeMediumVerified answerSQLite live

Movies per Genre

Return genre and movie_count for each genre, ordered by movie_count descending then genre alphabetically.

  • Aggregation
  • Sorting

Challenge brief

Understand the request

Content Strategy The content strategy team is assessing genre diversity in the catalog to identify underrepresented categories.

Count the number of titles in each genre.

Return

  • genre
  • movie_count

Constraints

  • Return one row per catalog genre
  • Order by movie count descending, then genre

Data you will use

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

movies

  • movie_idINTEGER
  • genreVARCHAR(50)

Hints, when you need them

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

Hint 1

Each catalog row contributes to one genre.

Hint 2

Count titles at genre grain.

Hint 3

Sort by the count and genre label.

Verified SQL answer

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

Reveal solution and explanation
SELECT genre, COUNT(*) AS movie_count FROM movies GROUP BY genre ORDER BY movie_count DESC, genre

Why this works

GROUP BY genre and COUNT(*) gives the catalog depth per genre. The secondary ORDER BY genre resolves the tie between Crime and Sci-Fi deterministically.

Success check

Returns the complete deterministic result for movies per genre

Expected result

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

genremovie_count
Crime2
Sci-Fi2
Action1
Documentary1
Drama1

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.