Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Data Manipulation in SQL

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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;
Code bewerken en uitvoeren