Get startedGet started for free

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 exercise is part of the course

Data Manipulation in SQL

View Course

Exercise instructions

  • Complete the CASE statement to identify Barcelona's away team games as wins, losses, or ties.
  • Left join the teams_spain table team_api_id column on the matches_spain table hometeam_id column. This retrieves the identity of the home team opponent.
  • Filter the query to only include matches where Barcelona (awayteam_id = 8634) 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
LEFT JOIN teams_spain AS t 
ON m.hometeam_id = t.team_api_id
-- Filter for Barcelona
WHERE m.___ = ___;
Edit and Run Code