0% found this document useful (0 votes)
11 views2 pages

PROBLEM STATEMENT-Football Match Score DA Interview

The document outlines a SQL problem for a Data Analyst interview, requiring the computation of points for football teams based on match results. It provides the structure of two tables, 'teams' and 'matches', and specifies the scoring rules for wins, draws, and losses. The task is to write an SQL query that ranks teams by their points and includes sample input data and expected output format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

PROBLEM STATEMENT-Football Match Score DA Interview

The document outlines a SQL problem for a Data Analyst interview, requiring the computation of points for football teams based on match results. It provides the structure of two tables, 'teams' and 'matches', and specifies the scoring rules for wins, draws, and losses. The task is to write an SQL query that ranks teams by their points and includes sample input data and expected output format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Analyst Interview (4+ yrs experience)

Task: SQL Problem solving


Problem Statement:
Given a list of matches in the group stage of the football World Cup, compute the number of points
each team currently has.
You are given two tables, “teams” and “matches”, with the following structures:

CREATE TABLE teams


(
team_id INT primary key,
team_name VARCHAR(50) not null
);

CREATE TABLE matches


(
match_id INT primary key,
host_team INT,
guest_team INT,
host_goals INT,
guest_goals INT
);

Description:
Each record in the “teams” table represents a single football team. Each record in the “matches”
table represents a finished match between two teams.
Teams (“host_team”, “guest_team”) are represented by their IDs in the “teams” table (“team_id”).
No team plays a match against itself. You know the result of each match (i.e., the number of goals
scored by each team).

You would like to compute the total number of points each team has scored after all the matches
described in the table. The scoring rules are as follows:
 If a team wins a match (scores strictly more goals than the other team), it receives three
points.
 If a team draws a match (scores exactly the same number of goals as the opponent), it
receives one point.
 If a team loses a match (scores fewer goals than the opponent), it receives no points.

Write an SQL query that returns a ranking of all teams (“team_id”) described in the “teams” table.
For each team, you should provide its name and the number of points it received after all described
matches (“num_points”). The table should be ordered by “num_points” (in decreasing order). In case
of a tie, order the rows by “team_id” (in increasing order).

Sample input data:


| team_id | team_name |
|------------|------------------|
| 10 | Give |
| 20 | Never |
| 30 | You |
| 40 | Up |
| 50 | Gonna |
| match_id | host_team | guest_team | host_goals | guest_goals |
|--------------|----------------|-----------------|----------------|------------------|
| 1 | 30 | 20 | 1 | 0 |
| 2 | 10 | 20 | 1 | 2 |
| 3 | 20 | 50 | 2 | 2 |
| 4 | 10 | 30 | 1 | 0 |
| 5 | 30 | 50 | 0 | 1 |

Expected output:
| team_id | team_name | num_points |
|------------|------------------|-----------------|
| 20 | Never | 4 |
| 50 | Gonna | 4 |
| 10 | Give | 3 |
| 30 | You | 3 |
| 40 | Up | 0 |

You might also like