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
___
This exercise is part of the course
Intermediate SQL
Accompanied at every step with hands-on practice queries, this course teaches you everything you need to know to analyze data using your own SQL code today!
This final chapter teaches you how to sort and group data. These skills will take your analyses to a new level by helping you uncover critical business insights and identify trends and performance. You'll get hands-on experience to determine which films performed the best and how movie durations and budgets changed over time.
Exercise 1: Sorting resultsExercise 2: Sorting textExercise 3: Sorting single fieldsExercise 4: Sorting multiple fieldsExercise 5: Grouping dataExercise 6: GROUP BY single fieldsExercise 7: GROUP BY multiple fieldsExercise 8: Answering business questionsExercise 9: Filtering grouped dataExercise 10: Filter with HAVINGExercise 11: HAVING and sortingExercise 12: All together nowExercise 13: Congratulations!What is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.