If I have table that contains data for all the teams from many leagues, how I can get the first team from each league? The first team in each league should be the team with most point, or if points are equal the team with best goal difference (GF-GA)
For example:
League | Team | GF | GA | Points |
---|---|---|---|---|
Champion Group A | Bayren | 18 | 5 | 16 |
Champion Group A | Atlteico Madrid | 7 | 8 | 9 |
Champion Group H | PSG | 13 | 6 | 12 |
Champion Group H | RB Leipzig | 11 | 12 | 12 |
I want to get result like:
League | Team |
---|---|
Champion Group A | Bayren |
Champion Group H | PSG |
SELECT TEAM, LEAGUE
FROM LEAGUES_TABLE
GROUP BY LEAGUE
HAVING MAX(POINTS) //or if point equal use MAX(GF-GA)