IntermediateWindow Functions25 points

The top scorer of every club (ties included)

Each club wants a poster of its leading marksman. In goals every goal records the scoring player (player_id) and the club he scored for (club_id). Careful: four players moved clubs in the January window, so a player's goals must be counted per club he scored for, using goals.club_id and not players.club_id.

When two or more players share the club's highest tally they all get a poster.

Task: return club (name), player (name) and goals (goals scored for that club) for every player whose count equals the best count at that club. Sort by club A to Z, then by player A to Z.

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?

RANK() gives tied players the same number, so keep the rows where the rank is 1.