Baselight
WITH cr7_stats as 
(SELECT p.name as player, t.name as team, s.season_label as season, c.name as competition,
  m.date as match_date, home_teams.name as home_team, away_teams.name as away_team, 
  (EXTRACT(YEAR FROM match_date) - 1985) AS age,
  mps.*
FROM @blt.ultimate_soccer_dataset.match_player_stats mps
     INNER JOIN @blt.ultimate_soccer_dataset.matches m on (mps.match_id = m.match_id)
     INNER JOIN @blt.ultimate_soccer_dataset.players p on (mps.player_id = p.player_id)
     INNER JOIN @blt.ultimate_soccer_dataset.teams t on (mps.team_id = t.team_id)
     INNER JOIN @blt.ultimate_soccer_dataset.seasons s on (m.season_id = s.season_id)
     INNER JOIN @blt.ultimate_soccer_dataset.competitions c on (s.competition_id = c.competition_id)
     INNER JOIN @blt.ultimate_soccer_dataset.teams home_teams ON (m.home_team_id = home_teams.team_id)
     INNER JOIN @blt.ultimate_soccer_dataset.teams away_teams ON (m.away_team_id = away_teams.team_id)
WHERE p.player_id = '5b578ccf-496a-5afb-bea2-c7ece1b2c05b' -- Cristiano Ronaldo
      and year(m.date) >= 2015
      and mps.minutes_played > 0      
)

SELECT age, 
  COUNT(*) AS matches, SUM(goals_scored) as goals, ROUND(goals/matches, 2) AS goals_per_match,
  SUM(minutes_played) as mins_played, ROUND(goals/mins_played*90, 2) as goals_per_90_mins,
  list(DISTINCT team) FILTER (team <> 'Portugal') AS clubs
FROM cr7_stats
GROUP BY age
ORDER BY age
agematchesgoalsgoals_per_matchmins_playedgoals_per_90_minsclubs
3023251.0920701.09Real Madrid
3149410.8443280.85Real Madrid
3243380.8838690.88Real Madrid
3343410.9536101.02Juventus,Real Madrid
3448380.7941110.83Juventus
354343137801.02Juventus
3654380.745090.76Juventus,Manchester United
3744160.3632870.44Manchester United
3836350.9732510.97Al-Nassr
3940340.8534530.89Al-Nassr
4022180.8219100.85Al-Nassr

Share link

Anyone who has the link will be able to view this.