CASE statements comparing two column values part 2
Similar to the previous exercise, you will construct a query to determine the outcome of Barcelona's matches where they played as the away team. You will learn how to combine these two queries in chapters 2 and 3.
Did their performance differ from the matches where they were the home team?
This is a part of the course
“Data Manipulation in SQL”
Exercise instructions
- Complete the
CASE
statement to identify Barcelona's away team games (id = 8634
) as wins, losses, or ties. - Left join the
teams_spain
tableteam_api_id
column on thematches_spain
tablehometeam_id
column. This retrieves the identity of the home team opponent. - Filter the query to only include matches where Barcelona was the away team.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Select matches where Barcelona was the away team
SELECT
m.date,
t.team_long_name AS opponent,
___ ___ ___ < ___ ___ 'Barcelona win!'
WHEN ___ > ___ ___ 'Barcelona loss :('
___ 'Tie' ___ ___ outcome
FROM matches_spain AS m
-- Join teams_spain to matches_spain
LEFT JOIN teams_spain AS t
ON m.___ = t.___
WHERE m.___ = ___;