Get Started

The average length of films by category

From the previous exercise you've learned that the tables film and category have the necessary information to calculate the average movie length for every category. You've also learned that they share a common field film_id which can be used to join these tables. Now you will use this information to query a list of average length for each category.

This is a part of the course

“Applying SQL to Real-World Problems”

View Course

Exercise instructions

  • Calculate the average length and return this column as average_length.
  • Join the two tables film and category.
  • Ensure that the result is in ascending order by the average length of each category.

Hands-on interactive exercise

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

-- Calculate the average_length for each category
SELECT category, 
	   ___ AS average_length
FROM ___ AS f
-- Join the tables film & category
INNER JOIN ___ AS c
  ON f.___ = c.___
GROUP BY ___
-- Sort the results in ascending order by length
___;

This exercise is part of the course

Applying SQL to Real-World Problems

IntermediateSkill Level
4.6+
14 reviews

Find tables, store and manage new tables and views, and write maintainable SQL code to answer business questions.

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free