Basically I am doing a movie rental company database.
I need to be able to Give the names of movies that made more money than any other movie within their category.
Currently, I have a product table and rental table.
Product –
Attributes: (Product_ID, Product_Title, Rating, Release_Date, Genre, Length_of_Movie, Director_Name, Key_Actor, Num_Copies)
PK – Product_ID
Rental –
Attributes: (Rental_ID, Member_ID, Product_ID, Date_Rented, Date_Returned)
PK – Rental_ID
FK – Member_ID, Product ID
Each rental has a value of $1.00. I was able able to get the revenue of all the rentals, but I am struggling to get it by genre or category. I got the revenue as a whole by this query:
Select sum(count(Rental_ID) *1) as Revenue
from Rental
Group by Rental_ID;
** every rental is $1.00 so it was a simple calculation to just count how many times a unique rental number was created and multiply it by the flat fee.
I now need to break that down, and give the highest earner per genre or category. I’m completely stumped… any help would be appreciated. Thanks.
I haven’t test this but:
I’d create a view to get revenue per product like so
To get the maximum earnings by Genre you can utilise the view, and I’ll make another view called MaxRevenueByGenre.
To get the product (or products) that had the maximum revenue per genre is a bit more tricky as you need to refer to the revenue part twice. You’ll notice both views are used.
This will produce more than one result for each Genre if they are tied for highest earner.
You can get by without views, by substituting the select statements of the view inside parenthesis if you prefer.