BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Data Manipulation in SQL

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

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

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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;
Kodu Düzenle ve Çalıştır