1. Learn
  2. /
  3. Courses
  4. /
  5. Data Manipulation in SQL

Exercise

Subqueries in Select for Calculations

Subqueries in SELECT are a useful way to create calculated columns in a query. A subquery in SELECT can be treated as a single numeric value to use in your calculations. When writing queries in SELECT, it's important to remember that filtering the main query does not filter the subquery -- and vice versa.

In the previous exercise, you created a column to compare each league's average total goals to the overall average goals in the 2013/2014 season. In this exercise, you will add a column that directly compares these values by subtracting the overall average from the subquery.

Instructions

100 XP
  • Select the average goals scored in a match for each league in the main query.
  • Select the average goals scored in a match overall for the 2013/2014 season in the subquery.
  • Subtract the subquery from the average number of goals calculated for each league.
  • Filter the main query so that only games from the 2013/2014 season are included.