SQL Statement for Postgres:
SELECT
c.name AS category,
ROUND(AVG(f.length), 2) AS average_length
FROM
film f
JOIN film_category fc ON f.film_id = fc.film_id
JOIN category c ON fc.category_id = c.category_id
GROUP BY
c.name;
Explanation:
film
, film_category
, and category
tables to calculate the average length of movies in each category.JOIN
keyword is used to combine the tables based on their respective foreign key relationships.GROUP BY
clause is used to group the results by the category name.AVG
function is used to calculate the average length of movies in each category.ROUND
function is used to round the average length to 2 decimal places.