Get startedGet started for free

In CASE of rivalry

Barcelona and Real Madrid have been rival teams for more than 80 years. Matches between these two teams are given the name El Clásico (The Classic). In this exercise, you will query a list of matches played between these two rivals, where Barcelona is the home team, categorizing as a home or away win depending on multiple conditions.

This exercise is part of the course

Data Manipulation in SQL

View Course

Exercise instructions

  • Construct the CASE statement identifying who won each match.
  • Fill in the logical operators to identify Barcelona or Real Madrid as the winner.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT 
	date,
	CASE WHEN hometeam_id = 8634 THEN 'FC Barcelona' 
         ELSE 'Real Madrid CF' END as home,
	CASE WHEN awayteam_id = 8634 THEN 'FC Barcelona' 
         ELSE 'Real Madrid CF' END as away,
	-- Identify possible home match outcomes
	___ ___ home_goal > away_goal ___ hometeam_id = 8634 ___ 'Barcelona win!'
        WHEN home_goal < away_goal ___ awayteam_id = 8633 ___ 'Real Madrid win!'
        ___ 'Tie!' ___ ___ outcome
FROM matches_spain
WHERE hometeam_id = 8634 AND awayteam_id = 8633;
Edit and Run Code