What is the average length of movies in each category? 2 decimals.
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:
- The SQL statement uses the
film,film_category, andcategorytables to calculate the average length of movies in each category. - The
JOINkeyword is used to combine the tables based on their respective foreign key relationships. - The
GROUP BYclause is used to group the results by the category name. - The
AVGfunction is used to calculate the average length of movies in each category. - The
ROUNDfunction is used to round the average length to 2 decimal places. - The result will include the category name and the average length of movies in that category.
- Public
- ·
- Thu, 24 Aug 2023 08:03:05 GMT