Conditional selection and summation with CASE WHEN
You can use CASE statements to apply a constraint and run a calculation by including the statement inside an aggregate function like SUM()!
In this exercise, your goal is to filter for a specific team (Real Sociedad) and calculate their total home and away goals per season.
Bu egzersiz
Data Manipulation in SQL
kursunun bir parçasıdırEgzersiz talimatları
- Create a
CASEstatement to calculate the total number of home goals where thehometeam_idis8560. - Create a second
CASEstatement to calculate the total number of away goals where theawayteam_idis8560, aliasing the column asaway_goals. - Group the query by
season.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
SELECT season,
-- SUM the home goals
___(___ ___ hometeam_id = 8560 THEN ___ END) AS home_goals,
-- SUM the away goals
___
FROM match
-- Group the results by season
___