LEFT JOIN on the Teams table with the Matches table, joining on the condition that the team_id matches either the host_team or guest_team.CASE statement within the SUM function to calculate the points for each team based on the match results.team_id and team_name to get the total points for each team.num_points in descending order and by team_id in ascending order to break ties.team_id, team_name, and the calculated num_points for each team.
erDiagram
Teams {
int team_id PK
varchar team_name
}
Matches {
int match_id PK
int host_team FK
int guest_team FK
int host_goals
int guest_goals
}
Teams ||--o{ Matches : plays