---
title: "Code Challenge: World Cup SQL | CoderPad"
description: "The FIFA World Cup is a global sporting event where national soccer teams compete to determine the world champion every four years! Use your SQL knowledge to discover exciting world cup history facts like “which team has the largest world cup following in FIFA history?” Use the sandbox below to get started and practice"
canonical: "https://coderpad.io/blog/coding-challenges/tiny-interviews-world-cup-sql/"
last_modified: "2026-04-15 16:21:03"
---
[Back to blog](https://coderpad.io/blog/)

# Code Challenge: World Cup SQL

November 23, 2022 2 Minute Read

By Mathis Hammel

[Coding Challenges](https://coderpad.io/blog/coding-challenges/)

The FIFA World Cup is a global sporting event where national soccer teams compete to determine the world champion every four years! Use your SQL knowledge to discover exciting world cup history facts like “which team has the largest world cup following in FIFA history?” Use the sandbox below to get started and practice your SQL skills!

>

💡 Warm up your SQL skills with this article on [SQL functions and techniques every data person should know](https://coderpad.io/blog/development/sql-functions-and-techniques-every-data-person-should-know/).

Please see the interview prompts written directly in the pad. Question solutions are provided in the next section after the sandbox.

>

‼️ Attempt the questions in the pad before checking out the solutions.

## Useful tips

Running SQL: Comment out any SQL code from a previous question before moving to the next Question (or else all your SQL code will run at once). You can do this quickly by:

1. Highlighting your code
2. Typing`Cmd + /`or`Ctrl + /`

### Viewing data

To view all data in a single row easily, replace the semicolon at the end of your query with`/G`.

Example:

— Returns a single row in a vertical, easy to ready format

`select * from World_Cup_Matches limit 1 \G`

— Returns a single row in a horizontal format, better suited for a wide screen

`select * from World_Cup_Matches limit 1;`

## Interview data

The data for the tiny interview can be viewed on this [kaggle dataset](https://www.kaggle.com/datasets/abecklas/fifa-world-cup?select=WorldCupMatches.csv).

CoderPad provides a basic SQL sandbox with the following schema. You can also use commands like`show tables`and`desc world_cup_tournaments`.

The schema diagram for the`world_cup_tournaments`,`world_cup_matches`and`world_cup_line_ups`table.

## Solutions

### Question 1

Learn the skills needed:

ORDER BY: [https://www.w3schools.com/sql/sql_orderby.asp](https://www.w3schools.com/sql/sql_orderby.asp)

```
select
Year
, Host_Country
, Goals_Scored
from world_cup_tournaments
order by Goals_Scored desc Code language: SQL (Structured Query Language) (sql)
```

### Question 2

Learn the skills needed:

- LEFT JOIN: [https://www.w3schools.com/sql/sql_join_left.asp](https://www.w3schools.com/sql/sql_join_left.asp)
- COUNT(): [https://www.w3schools.com/sql/func_mysql_count.asp](https://www.w3schools.com/sql/func_mysql_count.asp)
- GROUP BY: [https://www.w3schools.com/sql/sql_groupby.asp](https://www.w3schools.com/sql/sql_groupby.asp)
- ORDER BY: [https://www.w3schools.com/sql/sql_orderby.asp](https://www.w3schools.com/sql/sql_orderby.asp)

```
select
  a.Year
  , a.Host_Country
  , count(distinct b.Stadium) as num_pitch_locations
from
  world_cup_tournaments as a
  left join world_cup_matches as b on a.Year = b.Year
group by 1,2
order by 3 desc Code language: SQL (Structured Query Language) (sql)
```

### Question 3

Learn the skills needed:

- Common Table Expressions (CTE): [https://www.w3schools.blog/sql-cte-how-to-master-it-with-easy-examples](https://www.w3schools.blog/sql-cte-how-to-master-it-with-easy-examples) [https://mariadb.com/kb/en/non-recursive-common-table-expressions-overview/](https://mariadb.com/kb/en/non-recursive-common-table-expressions-overview/)
- ORDER BY: [https://www.w3schools.com/sql/sql_orderby.asp](https://www.w3schools.com/sql/sql_orderby.asp)

```
with calculate_avg_goals_per_match as (
  select
    Year
    , Host_Country
    , Goals_Scored / Matches_Played as avg_goals_per_match
  from world_cup_tournaments
)
select *
from calculate_avg_goals_per_match
order by avg_goals_per_match descCode language: SQL (Structured Query Language) (sql)
```

### Question 4

Learn the skills needed:

- Common Table Expressions (CTE): [https://www.w3schools.blog/sql-cte-how-to-master-it-with-easy-examples](https://www.w3schools.blog/sql-cte-how-to-master-it-with-easy-examples) [https://mariadb.com/kb/en/non-recursive-common-table-expressions-overview/](https://mariadb.com/kb/en/non-recursive-common-table-expressions-overview/)
- UNION ALL: [https://www.w3schools.com/sql/sql_ref_union_all.asp](https://www.w3schools.com/sql/sql_ref_union_all.asp)
- ORDER BY: [https://www.w3schools.com/sql/sql_orderby.asp](https://www.w3schools.com/sql/sql_orderby.asp)
- SUM(): [https://www.w3schools.com/mysql/func_mysql_sum.asp](https://www.w3schools.com/mysql/func_mysql_sum.asp)
- LIMIT: [https://www.w3schools.com/mysql/mysql_limit.asp](https://www.w3schools.com/mysql/mysql_limit.asp)

```
with list_matches_with_attendance as (
  -- List stadium_attendance for Home_Team_Name
  select
    Match_ID
    , Home_Team_Name as team_name
    , Attendance as stadium_attendance
  from world_cup_matches

  UNION ALL

  -- List all stadium_attendance for Away_Team_Name
  select
    Match_ID
    , Away_Team_Name as team_name
    , Attendance as stadium_attendance
  from world_cup_matches
)
select
  team_name
  , sum(stadium_attendance) as team_following
from list_matches_with_attendance
group by 1
order by 2 desc
limit 10Code language: SQL (Structured Query Language) (sql)
```

## More interviewing resources

Even for the most experienced managers, hiring the right engineers can be tricky.

To make it easier, here are some more resources to help make your hiring process as smooth as possible:

- [SQL interview questions](https://coderpad.io/blog/interviewing/sql-interview-questions/)
- [A Holistic Guide to Diversity and Inclusion in the Technical Hiring Process](https://coderpad.io/blog/interviewing/a-holistic-guide-to-diversity-and-inclusion-in-the-technical-hiring-process/)
- [25+ questions for MySQL](https://coderpad.io/interview-questions/mysql-interview-questions/)
- [25+ questions for PostgreSQL](https://coderpad.io/interview-questions/postgresql-interview-questions/)
- [Online coding test questions for MySQL](https://coderpad.io/online-coding-tests/mysql-online-coding-test/)
- [Online coding test questions for PostgreSQL](https://coderpad.io/online-coding-tests/postgresql/)

## Subscribe for more CoderPad insights

## Trending Articles

Previous slide Next slide [Coding Challenges

## Code Challenge: Hotel Booking Demand

This two part challenge aims to test your understanding of how you can interact with data and explore it to unveil important hidden information as well as craft visualizations that spotlight various aspects of the dataset.

Read the post](https://coderpad.io/blog/coding-challenges/code-challenge-hotel-booking-demand/) [Coding Challenges

## Code Challenge: Consuming API In Spring

In Spring applications, consuming APIs is a common requirement for interacting with external services or fetching data from remote servers. Complete the API consumption methods for the students endpoints in this code challenge.

Read the post](https://coderpad.io/blog/coding-challenges/code-challenge-consuming-api-in-spring/) [Coding Challenges

## Code Challenge: Django Models

Django is a popular Python framework for building web applications. Test your knowledge of models by improving the Django application in this code challenge.

Read the post](https://coderpad.io/blog/coding-challenges/code-challenge-django-models/) [Coding Challenges

## Code Challenge: Responsiveness in HTML

This coding challenge tests your knowledge on responsiveness and creating interactive websites. Take a stab at the tasks in this challenge!

Read the post](https://coderpad.io/blog/coding-challenges/coding-challenge-responsiveness-in-html/) [Coding Challenges

## Code Challenge: Simple Search

For this code challenge, you are provided with a website that has a vulnerability. Can you fix it?

Read the post](https://coderpad.io/blog/coding-challenges/coding-challenge-simple-search/) [Coding Challenges

## Code Challenge: Toggle With CSS

Test your understanding of HTML & CSS by completing the tasks in this code challenge.

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-toggle-with-css/) [Coding Challenges

## Code Challenge: Python Longest Subarray

In a street with colored houses, you want to take a picture containing the most houses, but without any duplicate colors. Can you solve this problem involving unique values?

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-python-longest-subarray/) [Coding Challenges

## Code Challenge: React Controlled Input

State management is a method of controlling communication between different parts of state and their usage, including React components. Test your knowledge on state management by improving the React app in this code challenge.

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-react-controlled-input/) [Coding Challenges

## Code Challenge: Django Search Filter

Django is a popular Python framework for building web applications. Test your Django knowledge by improving the search filter application in this tiny interview.

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-django-search-filter/) [Coding Challenges

## Code Challenge: Vue Counter App

Vue is a popular JavaScript library for building frontend applications and user interfaces. It builds on HTML, CSS and JavaScript and employs a declarative model for building components. Test your Vue knowledge by improving the counter application in this code challenge.

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-vue-counter-app/) [Coding Challenges

## Code Challenge: Python Unit Testing

Unit tests ideally test a small unit (or rather, amount) of code. For this code challenge, we have created 20 bad functions, write testcases to break them all!

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-python-unit-testing/) [Coding Challenges

## Code Challenge: Python Move Zeros

In this code challenge, the provided function works but is very slow on larger inputs. Can you make it faster?

Read the post](https://coderpad.io/blog/coding-challenges/tiny-interview-python-move-zeros/)

## Hire with confidence.

See why engineering teams trust CoderPad to evaluate developers with realistic, AI-ready hiring workflows.

[Request a demo](https://coderpad.io/sales/)
