Posted by Dania, Oct. 17, 2022, 2:07 a.m.
Question 40
Hi, can anyone help me with what's wrong with my code?
Question:
- Write a query to return the
film_idandtitleof the top 2 movies that were rented the most times in June 2020 - Use the
rental_tscolumn from therentalfor the transaction time. - The order of your results doesn't matter.
My code (using Postgres):
SELECT a.film_id, a.title
FROM film a
JOIN inventory b
ON a.film_id = b.film_id
JOIN (SELECT inventory_id,
EXTRACT(YEAR FROM rental_ts) as year_,
EXTRACT(MONTH FROM rental_ts) as mon_,
count(rental_id)
FROM rental
WHERE EXTRACT(YEAR FROM rental_ts) = 2020
AND EXTRACT(MONTH FROM rental_ts) = 6
GROUP BY 1,2,3
ORDER BY 4 DESC
LIMIT 2) c
ON b.inventory_id = c.inventory_id
The result is different with the expected result