1. Learn
  2. /
  3. Courses
  4. /
  5. Data Manipulation in SQL

Exercise

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.

You will notice in Step 2 that when you have multiple logical conditions in a CASE statement, you may quickly end up with a large number of WHEN clauses to logically test every outcome you are interested in. It's important to make sure you don't accidentally exclude key information in your ELSE clause.

In this exercise, you will retrieve information about matches played between Barcelona (id = 8634) and Real Madrid (id = 8633). Note that the query you are provided with already identifies the Clásico matches using a filter in the WHERE clause.

Instructions 1/2

undefined XP
    1
    2
  • Complete the first CASE statement, identifying Barcelona or Real Madrid as the home team using the hometeam_id column.
  • Complete the second CASE statement in the same way, using awayteam_id.