MYSQL GROUP BY MAX得分 [英] MYSQL GROUP BY MAX score

查看:135
本文介绍了MYSQL GROUP BY MAX得分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为scores的表,其中包含列

I have a table called scores which contains columns

如何选择哪个id_team是每场得分最高的得分手

How do I select which id_team is top scorer per game

我正在尝试这样做,但这不是正确的结果

i m trying with this, but that's not correct result

SELECT MAX( score ) , id_team
FROM scores
GROUP BY  `id_game` 
LIMIT 0 , 30

推荐答案

您可以使用自我加入来找出得分最高的游戏a的正确团队ID

You can use a self join to find out the right team id for game a which has max score

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

这篇关于MYSQL GROUP BY MAX得分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆