Created
November 5, 2019 04:46
-
-
Save Nocks/1e953ab3af212a4d80e45e0f560e82a7 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Who are the top 5 active customers who have spent most in renting films? | |
*/ | |
SELECT DISTINCT customer.customer_id, CONCAT(first_name, ' ', last_name) AS customer, | |
SUM(payment.amount) OVER(PARTITION BY customer) AS total_amt_spent | |
FROM customer | |
JOIN payment | |
ON customer.customer_id = payment.customer_id | |
WHERE customer.active = 1 | |
ORDER BY total_amt_spent DESC | |
LIMIT 5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment