Last active
November 6, 2019 00:07
-
-
Save Nocks/c7d22e52f622b24cef234e1b8221944a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
What are the top 10 film categories where most money have been received? | |
*/ | |
SELECT DISTINCT category.category_id, | |
category.name category, | |
COUNT(category) OVER(PARTITION BY category) AS rental_count, | |
ROUND(AVG(payment.amount) OVER(PARTITION BY category), 2) AS avg_amt_received, | |
SUM(payment.amount) OVER(PARTITION BY category) AS total_amt_received | |
FROM film | |
JOIN film_category | |
ON film_category.film_id = film.film_id | |
JOIN category | |
ON film_category.category_id = category.category_id | |
JOIN inventory | |
ON film.film_id = inventory.film_id | |
JOIN rental | |
ON inventory.inventory_id = rental.inventory_id | |
JOIN payment | |
ON rental.rental_id = payment.rental_id | |
ORDER BY total_amt_received DESC | |
LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment