JOIN team_dim ftd ON m.first_team = ftd.team_name JOIN team_dim std ON m.second_team = std.team_name max(case when d.country = m.first_team then d.over else 0 end ...