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
, andcategory
tables to calculate the average length of movies in each category. - The
JOIN
keyword is used to combine the tables based on their respective foreign key relationships. - The
GROUP BY
clause is used to group the results by the category name. - The
AVG
function is used to calculate the average length of movies in each category. - The
ROUND
function 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