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

Connected

Exercise

Add a subquery in FROM

In the previous exercise, you created a data set listing the average home and away goals in each match stage of the 2012/2013 match season.

In this next step, you will turn the main query into a subquery to extract a list of stages where the average total goals in a stage is higher than the overall average for total goals in a match.

Instructions

100 XP
  • Calculate the average total goals from the match table for each stage in the FROM clause subquery.
  • Add a subquery to the WHERE clause that calculates the overall average total goals.
  • Filter the main query for stages where the average total goals is higher than the overall average.
  • Select the stage and avg_goals columns from the s subquery into the main query.