Analyzing Customer Rental Trends: Identifying Popular Movie Genres Across Multiple Months
Description:
You work for a DVD rental store that wants to understand which movie genres are the most popular among customers who have rented at least one movie during multiple months. By analyzing rental data over a longer period of time, the store owner hopes to gain insights into most active customer's preferences and identify trends that can inform their business decisions as well as which genres may be experiencing a surge or decline in popularity.
Your task is to write a SQL query to identify the top five most popular movie genres among customers who have rented at least one movie
during the months of May, June, and July of 2005 (in each
of these 3 months), regardless of whether they rented movies in other months.
Notes:
- for the sample tests, static dump of DVD Rental Sample Database is used, for the final solution - random tests.
- by
popularity
is meant the quantity of rentals by the eligible customers, regardless of the period in which the rental was made - by
genre
-category.name
fromcategory
table - List should be sorted by the quantaty of rentals from higher to lower and if number of rentals is the same - then by title of category alphabetically
Good luck!
Schema
customer
table:
Column | Type | Modifiers
------------ +----------+----------
customer_id | integer | not null
first_name | varchar | not null
last_name | varchar | not null
film
table:
Column | Type | Modifiers
-----------------+----------+----------
film_id | integer | not null
title | varchar | not null
description | text | not null
rating | varchar | not null
film_category
table:
Column | Type | Modifiers
------------+---------- +----------
film_id | smallint | not null
category_id | smallint | not null
category
table:
Column | Type | Modifiers
------------+-----------+----------
category_id | smallint | not null
name | text | not null
rental
table:
Column | Type | Modifiers
-------------+-----------+----------
rental_id | integer | not null
customer_id | integer | not null
inventory_id | integer | not null
rental_date | timestamp | not null
return_date | timestamp |
inventory
table:
Column | Type | Modifiers
------------ +-----------+----------
inventory_id | integer | not null
film_id | smallint | not null
store_id | smallint | not null
Desired Output
The desired output should look like this:
genre | total_rentals |
----------+----------------|
Action | 1035 |
Sci-Fi | 1004 |
Similar Kata:
Stats:
Created | Apr 21, 2023 |
Published | Apr 21, 2023 |
Warriors Trained | 307 |
Total Skips | 41 |
Total Code Submissions | 1005 |
Total Times Completed | 117 |
SQL Completions | 117 |
Total Stars | 14 |
% of votes with a positive feedback rating | 93% of 23 |
Total "Very Satisfied" Votes | 21 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |