BaşlayınÜcretsiz Başlayın

Add a subquery in SELECT

In the previous exercise, you added a subquery to the FROM statement and selected the stages where the number of average goals in a stage exceeded the overall average number of goals in the 2012/2013 match season. In this final step, you will add a subquery in SELECT to compare the average number of goals scored in each stage to the total.

Bu egzersiz

Data Manipulation in SQL

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a subquery in SELECT that yields the average total goals scored in the 2012/2013 season and stores it in a column named overall_avg
  • Create a subquery in FROM that calculates the average total goals scored in each stage during the 2012/2013 season.
  • Filter the main query for stages where the average total goals exceeds the overall average in 2012/2013.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

SELECT 
	-- Select the stage and average goals from s
	___,
    ROUND(___,2) AS avg_goal,
    -- Select the overall average for 2012/2013
    (___ ___(___ + away_goal) FROM ___ WHERE ___ = ___) AS overall_avg
FROM 
	-- Select the stage and average goals in 2012/2013 from match
	(SELECT
		 ___,
         ___(___ + away_goal) AS avg_goals
	 FROM ___
	 WHERE season = ___
	 GROUP BY stage) AS s
WHERE 
	-- Filter the main query using the subquery
	s.avg_goals ___ (SELECT ___(___ + away_goal) 
                    FROM match WHERE season = ___);
Kodu Düzenle ve Çalıştır