Baselight
WITH cristiano_ronaldo_match_player_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, 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
),
scoring_rate AS
  (SELECT match_date, EXTRACT(YEAR FROM match_date) - 1985 AS age, season, competition, team, format('{}-{}', home_team, away_team) as match
  --COUNT(*) AS matches,
  --COUNT(*) FILTER (WHERE goals_scored > 0) AS goals,
  --ROUND(100*ROUND(COUNT(*) FILTER (WHERE goals_scored > 0)::DECIMAL / COUNT(*)::DECIMAL, 3),0) AS scoring_rate
FROM cristiano_ronaldo_match_player_stats
WHERE minutes_played > 0
ORDER BY age)

SELECT
  team,  
    COUNT(*) AS matches,
    COUNT(*) FILTER (WHERE goals_scored > 0) AS goals,
    ROUND(100*ROUND(COUNT(*) FILTER (WHERE goals_scored > 0)::DECIMAL / COUNT(*)::DECIMAL, 3),0) AS scoring_rate
FROM cristiano_ronaldo_match_player_stats
WHERE minutes_played > 0
GROUP BY team



teammatchesgoalsscoring_rate
Al-Nassr825365
Portugal542444
Real Madrid1237158
Juventus1317356
Manchester United542037

Share link

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