365 Days of Daily Coding Challenge: Day 79
I am pleased with my performance today. I am becoming pro in solving challenges involving Windows function. I also tried solving another difficult challenge to get into the Top 10 leaderboard but unfortunately I was not able to solve it and I am bit tired to think and work on it.
Diffcult challenge link here
SELECT * FROM(
SELECT *, ROW_NUMBER() OVER(PARTITION BY name ORDER BY revenue DESC)
AS row_num FROM(
SELECT c.name, f.film_id, SUM(p.amount) AS revenue
FROM film_category f JOIN category c
ON f.category_id = c.category_id
LEFT JOIN inventory i
ON f.film_id = i.film_id
LEFT JOIN rental r
ON i.inventory_id = r.inventory_id
JOIN payment p
ON r.rental_id = p.rental_id
GROUP BY f.film_id, c.name) AS k)AS l
WHERE row_num < 3;

Leave a comment