IntermediateAnalytics Patterns25 points

Build the 2025-26 league table from raw results

The Atlantic Premier League's website lost its standings page, but every result of the 2025-26 season is still in matches (one row per game with home_goals and away_goals). The table must be rebuilt from scratch: a win is 3 points, a draw 1, a loss 0.

Hint for the approach: every match counts twice, once from the home side and once from the away side.

Task: return position, club (name), played, won, drawn, lost, goals_for, goals_against, goal_diff and points. Rank by points (high first), then goal difference (high first), then goals for (high first), then club name A to Z. position is 1, 2, 3, ... in that order with no repeated numbers. Sort the output by position.

The data you can query

Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.

clubs10 rows
club_id INTEGERname TEXTcity TEXTstadium_capacity INTEGER
1Harbor City FCHarbor City48000
2Rivermoor UnitedRivermoor36000
3Atlas AthleticPort Atlas41000
4Solent AlbionSolent Bay29000
5Kestrel TownKestrel22000
6Ironbridge WanderersIronbridge33000

Showing the first 6 of 10 rows.

goals222 rows
goal_id INTEGERmatch_id INTEGERplayer_id INTEGERclub_id INTEGERminute INTEGER
112153
215166
3262932
4214277
5321359
6321365

Showing the first 6 of 222 rows.

matches90 rows
match_id INTEGERseason TEXTmatchweek INTEGERmatch_date TEXThome_club_id INTEGERaway_club_id INTEGERhome_goals INTEGERaway_goals INTEGER
12025-2612025-08-0911020
22025-2612025-08-092911
32025-2612025-08-093822
42025-2612025-08-094723
52025-2612025-08-095631
62025-2622025-08-239100

Showing the first 6 of 90 rows.

players70 rows
player_id INTEGERname TEXTclub_id INTEGERposition TEXTnationality TEXTbirth_date TEXT
1Oliver Hughes1GKUnited Kingdom1996-02-16
2Mateusz Nowak1DFPoland2003-12-02
3Caleb Brooks1DFUnited States2000-06-16
4Nour Salem1MFEgypt2006-02-25
5Kofi Owusu1MFGhana1994-08-02
6Ethan Hayes8FWUnited States1995-10-27

Showing the first 6 of 70 rows.

transfers26 rows
transfer_id INTEGERplayer_id INTEGERfrom_club TEXTto_club_id INTEGERtransfer_date TEXTfee_musd REAL
12Dunmore Athletic12024-10-012.5
25Santa Rosa SC12024-11-058
38FC Lindenberg22025-07-1118
411Real Costa Verde22025-04-180
514Nordhavn IF22025-02-074
617Olympia Kallithea32024-09-1015

Showing the first 6 of 26 rows.

Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.

Need a hint?

UNION ALL the home view and the away view of every match into one list of (club, goals for, goals against), then group.