Get startedGet started for free

Adding and subtracting date and time values

In this exercise, you will calculate the actual number of days rented as well as the true expected_return_date by using the rental_duration column from the film table along with the familiar rental_date from the rental table.

This will require that you dust off the skills you learned from prior courses on how to join two or more tables together. To select columns from both the film and rental tables in a single query, we'll need to use the inventory table to join these two tables together since there is no explicit relationship between them. Let's give it a try!

This exercise is part of the course

Functions for Manipulating Data in PostgreSQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT f.title, f.rental_duration,
    -- Calculate the number of days rented
    ___.___ - ___.___ AS ___
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;
Edit and Run Code