MYSQL GROUP BY MAX metric

I have a table called score that contains columns

enter image description here

How to choose which id_team is the top scorer per game

im trying with this but what a wrong result

SELECT MAX( score ) , id_team
FROM scores
GROUP BY  `id_game` 
LIMIT 0 , 30
+4
source share
2 answers

You can use the independent connection to find out the correct team identifier for the game with the maximum rating

SELECT s.* 
FROM scores s
JOIN (
SELECT MAX(score) score, id_game 
FROM scores
GROUP BY id_game ) ss USING(score ,id_game )
LIMIT 0 , 30
+2
source
select A.id_game, A.id_team as winning_team
from scores A,
(
select max(score) as max, id_game
from scores
group by id_game
)B
where A.id_game = B.id_game
and A.score = B.max
0
source

Source: https://habr.com/ru/post/1537332/


All Articles