Team Dominance by Pass Success - Problem
You are given two tables: Teams and Passes. Write a SQL query to calculate the dominance score for each team in both halves of a football match.
Rules:
- A match is divided into two halves: first half (00:00-45:00 minutes) and second half (45:01-90:00 minutes)
- The dominance score is calculated based on successful and intercepted passes:
- When
pass_tois a player from the same team: +1 point - When
pass_tois a player from the opposing team (interception): -1 point - Return results ordered by
team_nameandhalf_numberin ascending order
A higher dominance score indicates better passing performance for that team in that half.
Table Schema
Teams
| Column Name | Type | Description |
|---|---|---|
player_id
PK
|
int | Unique identifier for each player |
team_name
|
varchar | Name of the team the player belongs to |
Primary Key: player_id
Passes
| Column Name | Type | Description |
|---|---|---|
pass_from
PK
|
int | Player ID who made the pass |
time_stamp
PK
|
varchar | Time when pass was made (MM:SS format) |
pass_to
|
int | Player ID who received the pass |
Primary Key: (pass_from, time_stamp)
Input & Output
Example 1 — Basic Match Analysis
Input Tables:
Teams
| player_id | team_name |
|---|---|
| 1 | Arsenal |
| 2 | Arsenal |
| 3 | Arsenal |
| 4 | Chelsea |
| 5 | Chelsea |
| 6 | Chelsea |
Passes
| pass_from | time_stamp | pass_to |
|---|---|---|
| 1 | 00:15 | 2 |
| 2 | 00:45 | 3 |
| 3 | 01:15 | 1 |
| 4 | 00:30 | 1 |
| 2 | 46:00 | 3 |
| 3 | 46:15 | 4 |
| 1 | 46:45 | 2 |
| 5 | 46:30 | 6 |
Output:
| team_name | half_number | dominance |
|---|---|---|
| Arsenal | 1 | 3 |
| Arsenal | 2 | 1 |
| Chelsea | 1 | -1 |
| Chelsea | 2 | 1 |
💡 Note:
First Half (00:00-45:00):
- Arsenal: 1→2 (+1), 2→3 (+1), 3→1 (+1) = +3
- Chelsea: 4→1 (-1, intercepted) = -1
Second Half (45:01-90:00):
- Arsenal: 2→3 (+1), 3→4 (-1, intercepted), 1→2 (+1) = +1
- Chelsea: 5→6 (+1) = +1
Example 2 — All Interceptions
Input Tables:
Teams
| player_id | team_name |
|---|---|
| 1 | TeamA |
| 2 | TeamB |
Passes
| pass_from | time_stamp | pass_to |
|---|---|---|
| 1 | 10:00 | 2 |
| 2 | 50:00 | 1 |
Output:
| team_name | half_number | dominance |
|---|---|---|
| TeamA | 1 | -1 |
| TeamB | 2 | -1 |
💡 Note:
Both passes were intercepted by the opposing team, resulting in negative dominance scores for both teams in their respective halves.
Constraints
-
1 ≤ player_id ≤ 1000 -
time_stampformat is'MM:SS'where00:00 ≤ time_stamp ≤ 90:00 -
team_nameconsists of alphanumeric characters only -
Each pass has valid
pass_fromandpass_toplayer IDs
Visualization
Tap to expand
Understanding the Visualization
1
Input Tables
Teams and Passes data
2
JOIN Analysis
Match passes with team information
3
Dominance Score
Calculate +1/-1 scores by half
Key Takeaway
🎯 Key Insight: Use double JOINs to compare passer and receiver teams for accurate dominance scoring
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code