Lesson 17.3
SQL Playground Mission: Movie Genre Scorecard
Turn rental history into a genre scorecard with counts and revenue.
A scorecard compresses transaction rows into a ranked view of performance. Here, each rental row contributes activity and revenue, while the movie table supplies the genre used for grouping.
The HAVING clause keeps the report focused on genres with enough activity to compare. That is a common playground move: group broadly, then tighten the report once you can see the shape of the data.
Pattern
select dimension,
count(*) as activity,
round(sum(amount), 2) as revenue
from fact_table
join dimension_table using (dimension_id)
group by dimension
having count(*) >= 3
order by revenue desc, dimensionSchema · Movie RentalsTable · rentals6 columns · 26 rows
Table · rentals
6 columns · 26 rowsOne row per rental. Movies still out have a null returned_date.
rental_id intcustomer_id intmovie_id intrental_date datereturned_date dateamount decimal
SchemaTable · movies5 columns · 12 rows
Table · movies
5 columns · 12 rowsOne row per movie in the catalog.
movie_id inttitle textgenre textrelease_year intrating decimal
Your task
Build a genre scorecard. Return genre, rentals, and revenue for genres with at least 3 rentals. Sort by revenue descending, then genre.
SQL Workbench
⌘↵ to run·
Expected answer
- Columns: genre, rentals, revenue.
- Rows: genres with at least 3 rentals.
- Thriller leads with 6 rentals and 29.94 revenue.