HAVING and sorting
Filtering and sorting go hand in hand and gives you greater interpretability by ordering our results.
Let's see this magic at work by writing a query showing what countries have the highest average film budgets.
This is a part of the course
“Intermediate SQL”
Exercise instructions
- Select the
country
and the average budget asaverage_budget
, rounded to two decimal, fromfilms
. - Group the results by
country
. - Filter the results to countries with an average budget of more than one billion (
1000000000
). - Sort by descending order of the
average_budget
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Select the country and average_budget from films
___
-- Group by country
___
-- Filter to countries with an average_budget of more than one billion
___
-- Order by descending order of the aggregated budget
___