You are given two tables: TeamPoints containing national teams and their current points, and PointsChange containing point changes for each team.
The global ranking is determined by:
- Teams sorted by points in descending order
- Ties broken by team name in lexicographical order
Your task is to:
- Update each team's points using the
points_changevalues - Calculate the ranking before and after the update
- Return the change in ranking for each team
Return the result showing team_id, name, and ranking_change (negative means rank improved, positive means rank worsened).
Table Schema
| Column Name | Type | Description |
|---|---|---|
team_id
PK
|
int | Unique team identifier |
name
|
varchar | Country name the team represents |
points
|
int | Current points in global rankings |
| Column Name | Type | Description |
|---|---|---|
team_id
PK
|
int | Unique team identifier |
points_change
|
int | Change in points (positive=increase, negative=decrease, 0=no change) |
Input & Output
| team_id | name | points |
|---|---|---|
| 1 | Brazil | 80 |
| 2 | Germany | 60 |
| 3 | Spain | 40 |
| team_id | points_change |
|---|---|
| 1 | -20 |
| 2 | 25 |
| 3 | -10 |
| team_id | name | ranking_change |
|---|---|---|
| 1 | Brazil | 1 |
| 2 | Germany | -1 |
| 3 | Spain | 0 |
Initially: Brazil (80pts, rank 1), Germany (60pts, rank 2), Spain (40pts, rank 3). After changes: Germany (85pts, rank 1), Brazil (60pts, rank 2), Spain (30pts, rank 3). Germany improved by 1 rank (-1), Brazil dropped by 1 rank (+1), Spain stayed the same (0).
| team_id | name | points |
|---|---|---|
| 1 | Italy | 50 |
| 2 | France | 50 |
| team_id | points_change |
|---|---|
| 1 | 0 |
| 2 | 0 |
| team_id | name | ranking_change |
|---|---|---|
| 2 | France | 0 |
| 1 | Italy | 0 |
Both teams have 50 points before and after changes. Since points are equal, rankings are determined by name lexicographically: France (rank 1), Italy (rank 2). No point changes means no ranking changes.
Constraints
-
1 ≤ team_id ≤ 1000 -
1 ≤ name.length ≤ 100 -
0 ≤ points ≤ 1000 -
-1000 ≤ points_change ≤ 1000 - Each team in TeamPoints appears exactly once in PointsChange