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_idINTEGERgenreVARCHAR(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, genreWhy 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.
| genre | movie_count |
|---|---|
| Crime | 2 |
| Sci-Fi | 2 |
| Action | 1 |
| Documentary | 1 |
| Drama | 1 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Airbnb
Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice.
Return to the complete interview preparation experience.