# Football Analytics Using Transfermarkt Data

For our Database Management Systems class, we had to pick a dataset, build a database, and use SQL to answer questions we could present in a dashboard. I suggested football because I follow it closely, and we agreed on it as a group. Transfermarkt fit the assignment because it had separate tables for matches, clubs, players, and appearances that we could join by ID.

We studied the Premier League, La Liga, Bundesliga, Serie A, and Ligue 1 from 2012/13 through 2022/23. The results, attendance, and player analyses use fixtures dated August 10, 2012, through June 4, 2023. We wanted to see whether clubs won more often at home, how large the recorded crowds were, and which players accumulated the most assists and cards during those seasons. We also tracked the available annual market value estimates for Erling Haaland, Kylian Mbappé, and Vinícius Júnior from 2015 through 2022.

## From CSVs to analysis tables

We used games, appearances, players, clubs, club games, and player valuations from the public Transfermarkt dataset. We selected the Premier League, La Liga, Bundesliga, Serie A, and Ligue 1 by competition ID to keep the comparison to domestic league results. The source starts in 2012/13 for all five leagues. We used a fixed window through 2022/23 and checked the fixture totals for every league and season. This gave us 19,985 dated results between August 10, 2012, and June 4, 2023. [Publisher’s data repository](https://github.com/dcaribou/transfermarkt-datasets) · [Source fingerprints](results/summary.json) · [Cohort query](sql/scope.sql)

We trimmed text, loaded game, club, and player IDs and counts as integers, and parsed dates before joining. Empty values became SQL nulls. A fixture has one row in the games table and two roles in the club-games table. We counted results at fixture level and used `UNION ALL` to put each side on its own row for the club comparison. We joined appearances to results by game ID, then checked that the competition, date, and club agreed. We counted appearances by game before joining them to the fixture results for the coverage check. That kept each fixture to one row. We grouped by player ID because the audit found 448 names shared by more than one player. [Integrity query](sql/integrity_audit.sql) · [Data checks](results/integrity_audit.csv)

The appearance analysis retains 564,129 rows across 19,984 fixtures. The one fixture without appearances, Cagliari–Roma on September 23, 2012, has a recorded 3–0 result awarded to Roma after the match was called off. We counted the official result in the venue analysis. Only recorded appearances feed the player metrics. [Italian Football Federation ruling](https://www.figc.it/it/federazione/news/cgf-respinto-il-ricorso-del-cagliari-contro-lo-0-3-a-tavolino-con-la-roma-re8y5u7o)

## How did home win rates change over time?

We divided home wins by recorded fixtures in each league and season. We pooled the leagues by dividing all home wins by all recorded fixtures. This accounts for differences in schedule size, including the 2019/20 Ligue 1 season, which ended early with 279 of 380 scheduled matches played. We checked the observed fixture counts against the expected totals for all 55 league seasons and used `LAG` to compare each league’s rate with its own prior season. [Home results query](sql/home_results.sql) · [Fixture coverage](results/league_coverage.csv) · [LFP meeting minutes](https://www.lfp.fr/assets/20200430_PV_Conseil_Administration_LFP_e824a457fa.pdf)

| Season | Home wins | Recorded results | Home win rate |
| --- | ---: | ---: | ---: |
| 2012/13 | 832 | 1,826 | 45.56% |
| 2013/14 | 851 | 1,826 | 46.60% |
| 2014/15 | 821 | 1,826 | 44.96% |
| 2015/16 | 810 | 1,826 | 44.36% |
| 2016/17 | 888 | 1,826 | 48.63% |
| 2017/18 | 828 | 1,826 | 45.35% |
| 2018/19 | 817 | 1,826 | 44.74% |
| 2019/20 | 761 | 1,725 | 44.12% |
| 2020/21 | 729 | 1,826 | 39.92% |
| 2021/22 | 781 | 1,826 | 42.77% |
| 2022/23 | 835 | 1,826 | 45.73% |

The pooled rate ranged from 48.63% in 2016/17 to 39.92% in 2020/21. To examine that low, we compared it with 2018/19, the last full season before COVID-19. All five leagues had lower home win rates, with the largest drop in the Premier League at 9.74 percentage points. The next season, rates rose in four leagues. Serie A fell again, from 41.05% to 38.95%. These league rates help a football writer check whether a club’s home record stands out. To estimate the effect of crowds, we would need match-by-match restrictions and a way to account for team strength, opponents, and scheduling. [Results by league and season](results/home_results.csv)

## Did clubs win more often at home?

We compared the 44 clubs with home and away results in every season from 2012/13 through 2022/23. This gives each club the same eleven-season window. Clubs that entered or left a league during that period fall outside this comparison. For each qualifying club, we pooled its wins and fixtures across the eleven seasons, calculated its home and away win rates, and subtracted the away rate from the home rate. We ranked that difference within each league using `DENSE_RANK()`, with ties sharing a rank. [Venue comparison query](sql/club_venue_comparison.sql)

Sevilla had La Liga's largest difference. They won 131 of 209 home fixtures, or 62.68%, and 67 of 209 away fixtures, or 32.06%. The subtraction is 62.68 minus 32.06, giving a difference of 30.62 percentage points. Everton led the Premier League comparison, winning 100 of 209 at home, or 47.85%, and 54 of 209 away, or 25.84%. Their difference was 22.01 percentage points. A club analyst can use both rates to identify teams whose results differ most between venues.

The same time window still produces different fixture counts across leagues. Bundesliga clubs had 187 matches per venue over eleven seasons because that league has 18 teams. Premier League, La Liga, and Serie A clubs in this comparison had 209 per venue. Ligue 1's shortened 2019/20 season leaves its qualifying clubs with fewer matches, sometimes unequal home and away totals. We show the counts beside the rates. [Club venue results](results/club_venue_comparison.csv) · [Club counts by season](results/club_roles.csv)

## How much attendance did the data record?

Attendance is the number of spectators recorded for a fixture. Average crowd is the sum of those recorded spectator counts divided by the number of fixtures with a figure. Reporting coverage measures how complete that information is, by dividing the fixtures with a figure by all fixtures. Both analyses use the same 2012/13–2022/23 league fixtures.

We grouped by league, season, and calendar month. For each group, we counted all fixtures and those with a reported attendance. We kept a separate count of reported zeros. Across the full study, 17,837 of 19,985 fixtures had a figure. The query leaves the average blank when a group has no reported crowds. Seasonal averages divide the season's total recorded spectators by its reported fixture count. [Attendance query](sql/attendance.sql)

| Season | Attendance reported | Recorded results | Coverage | Mean reported crowd |
| --- | ---: | ---: | ---: | ---: |
| 2018/19 | 1,823 | 1,826 | 99.84% | 30,854 |
| 2019/20 | 1,309 | 1,725 | 75.88% | 31,621 |
| 2020/21 | 155 | 1,826 | 8.49% | 3,856 |
| 2021/22 | 1,782 | 1,826 | 97.59% | 25,015 |

COVID-19 restrictions kept most Premier League matches in 2020/21 behind closed doors. Some grounds admitted limited crowds in December 2020, and all grounds could do so in May 2021. Across the five leagues, attendance coverage fell from 99.84% in 2018/19 to 8.49% in 2020/21. The 2020/21 average of 3,856 comes from 155 recorded crowds. The source leaves 1,671 fixtures blank. La Liga has five reported crowds and Ligue 1 has 67. A season-wide crowd estimate would require fixture-level reporting or verified restrictions. [Premier League account of COVID-19 restrictions](https://www.premierleague.com/en/news/1682374) · [Monthly attendance results](results/attendance.csv)

## Who led in assists and cards during 2012/13–2022/23?

These leaderboards count appearances, assists, and cards in the Premier League, La Liga, Bundesliga, Serie A, and Ligue 1 during the eleven study seasons. A player who moved between these leagues contributes the appearances recorded in each. The measured appearance dates run from August 10, 2012, through June 4, 2023.

We grouped appearance rows by player ID and league, then pooled counts and minutes across the five leagues. Assists per 90 uses rows with a nonnegative assist figure and 0 to 130 recorded minutes. The upper bound is a check for implausible minutes, and all appearance rows passed it. We chose 900 minutes, the equivalent of ten full matches, to keep a handful of appearances from dominating the rate ranking. We show the minutes behind each rate and count yellow and red cards separately. [Player query](sql/players.sql) · [Data checks](results/integrity_audit.csv)

| Player | Assists | Measured minutes | Assists per 90 |
| --- | ---: | ---: | ---: |
| Lionel Messi | 165 | 30,667 | 0.484 |
| Thomas Müller | 145 | 22,416 | 0.582 |
| Joe Gelhardt | 6 | 938 | 0.576 |

Messi led in total assists and Müller led in assists per 90. Gelhardt ranked second by rate, with six assists in 938 minutes. At a 450-minute minimum, Hope Akpan would lead on 469 minutes. Müller still leads at 1,800 minutes. Damián Suárez led in yellow cards with 110 in 289 appearances. He also had two reds. Five players tied for the most reds at six each. [Player results](results/players.csv)

## How did player estimates move over time?

We used Erling Haaland, Kylian Mbappé, and Vinícius Júnior as three examples with several years of data. This section follows calendar years. The available annual observations start in 2015 for Mbappé, 2016 for Haaland, and 2017 for Vinícius Júnior, and end in 2022. The valuation query uses `ROW_NUMBER()` to pick the latest recorded estimate for each player and calendar year. This gives us one figure per year even when a player received several updates. We kept its date visible and stopped at 2022, the last full calendar year within the match-study window. [Valuation query](sql/valuation.sql)

Haaland’s latest estimated value rose from €45m in December 2019 to €170m in November 2022. His 2022 estimate came more than a month before Mbappé’s, which matters when comparing values within the same year. The figures are estimates in nominal euros. To compare fees, we would need records of completed transfers and their terms.

| Player | Latest estimate in 2022 | Observation date |
| --- | ---: | --- |
| Kylian Mbappé | €180m | December 23 |
| Erling Haaland | €170m | November 3 |
| Vinícius Júnior | €120m | November 7 |

[Valuation results](results/valuation.csv)

## Tableau dashboard

The Tableau workbook has four dashboard tabs. Club results compares home and away win rates for clubs present throughout all eleven seasons and shows the fixture counts behind those rates, alongside the league-wide season trends. Attendance compares average recorded crowds by season and shows the number of reported crowds out of all fixtures in a separate coverage chart. Each season's mean divides its total recorded spectators by its reported matches. Player output has separate rankings for assists, yellow cards, and red cards during 2012/13–2022/23, with appearance counts beside the names. Market values tracks the last dated estimate for each player and calendar year through 2022.

The generated previews use the dashboard layouts and the data tables packaged inside the downloadable workbook. On the case page, the monthly attendance chart provides a closer look at reporting gaps. A month with fixtures but no attendance figures has an unavailable average and 0% coverage. A month with no fixtures has neither an average nor a coverage percentage. [Dashboard previews and workbook](https://sameer-bansal.com/football-analytics/#tableau) · [Run the analysis](README.md#reproduce-the-analysis)

## Conclusion

The league trends give us a benchmark for the home and away records of clubs present throughout the study. Sevilla won 62.68% of its home matches and 32.06% away. Across the five leagues during 2012/13–2022/23, Messi supplied the most assists, while Müller had the highest eligible rate per 90. We kept fixture counts beside club rates, playing time beside player totals, reporting coverage beside crowd averages, and observation dates beside valuations so readers can follow each comparison.

[Sameer Bansal](https://www.linkedin.com/in/sameerbansal-utd/), [Rajat Singh](https://www.linkedin.com/in/rajatsingh77/), [Aishwarya](https://www.linkedin.com/in/aishwarya789/), and [Abdullah Rafiq](https://www.linkedin.com/in/abdullah-rafiq97/). Database Management Systems at UT Dallas, taught by [Prof. Thiru Pandian](https://www.linkedin.com/in/thiru-p-2837b7a/). [Transfermarkt-derived dataset](https://github.com/dcaribou/transfermarkt-datasets)
