Solution to Activity 5.2
First, try to use a way of getting this data by querying the film
table and using GROUP BY
on the release year; however, this will only return information for years in which films have been released. In our database, all films are released in a single year. So, you want to generate a range of years and then join this with the data you have to make sure that all the years are included, even if there were no films released in that year according to our database. Follow these steps to complete this activity:
- Open the MySQL client and connect to the
sakila
database:USE sakila
This produces the following output:
- Inspect the result of the naive approach by writing the following query:
SELECT release_year, COUNT(*) FROM film WHERE release_year BETWEEN 2005 AND 2010 GROUP BY release_year;
This produces the following output: