У меня возникли проблемы с последним столбцом, в котором указывается количество дней между первой и последней датой аренды мов ie.
Мои инструкторы правильно выводят :
Мой неверный вывод . Некоторые выходные данные в моем days_between_first_and_last_rent на 1 день превышают выходные данные моих инструкторов:
Таблица аренды :
DATEDIFF находится прямо над предложением FROM внизу
-- NOW()'Jordan_Rasmussen' just shows my name in the output for my teacher
-- Get a list of film titles
SELECT NOW()'Jordan_Rasmussen',
f.title,
( -- Get the count of the inventory
SELECT COUNT(i2.inventory_id)
FROM inventory AS i2
WHERE i2.film_id = f.film_id
) AS inventory_count,
-- Get the count of the number of times a movie was rented
COUNT(r.rental_id) AS num_times_rented,
-- Determine the demand of the film by the number of times it was rented
-- If the film has no inventory, then its demand is 'no inventory'
CASE
WHEN COUNT(i.inventory_id) = 0 THEN 'No Inventory'
WHEN COUNT(r.rental_id) > 20 THEN 'Fire'
WHEN COUNT(r.rental_id) > 10 THEN 'Hot'
WHEN COUNT(r.rental_id) > 5 THEN 'Warm'
ELSE 'Flop'
END AS demand,
-- Get the date of the first time the movie was rented
MIN(DATE(r.rental_date)) AS first_date_rented,
-- Get the number of days between the first and last day the movie was rented
DATEDIFF(MAX(DATE(r.rental_date)),MIN(DATE(r.rental_date))) AS days_between_first_and_last_rent
FROM film AS f
LEFT JOIN inventory AS i ON f.film_id = i.film_id
LEFT JOIN rental AS r ON i.inventory_id = r.inventory_id
GROUP BY f.title
ORDER BY f.title
Я просто не знаю, почему Я получаю +1 за некоторые строки, но не все из них.