Calculating the expected return date
So now that you've practiced how to add and subtract timestamps and perform relative calculations using intervals, let's use those new skills to calculate the actual expected return date of a specific rental. As you've seen in previous exercises, the rental_duration is the number of days allowed for a rental before it's considered late. To calculate the expected_return_date you will want to use the rental_duration and add it to the rental_date.
Este exercício faz parte do curso
Functions for Manipulating Data in PostgreSQL
Instruções do exercício
- Convert
rental_durationby multiplying it with a 1-dayINTERVAL. - Add it to the rental date.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
SELECT
f.title,
r.rental_date,
f.rental_duration,
-- Add the rental duration to the rental date
___ '1' day ___ f.___ + ___ AS expected_return_date,
r.return_date
FROM film AS f
INNER JOIN inventory AS i ON f.film_id = i.film_id
INNER JOIN rental AS r ON i.inventory_id = r.inventory_id
ORDER BY f.title;