[英]MySQL query: select records with highest value in group
I have a MySQL table like this. 我有一个这样的MySQL表。
| season_id | round_1 | names | score_round_1
| 5 | 10 | John1 | 5
| 5 | 10 | John2 | 3
| 5 | 11 | John3 | 2
| 5 | 11 | John4 | 5
I want to select the records with highest score_round_1 in each round_1(10,11) group . 我想在每个round_1(10,11)组中选择具有最高score_round_1的记录。
In this case the first and last rows would be selected. 在这种情况下,将选择第一行和最后一行。
I tried using the GROUP BY round_1 but that only returns the first row from the two. 我尝试使用GROUP BY round_1,但这仅返回两者的第一行。
Any advice? 有什么建议吗?
Zolka 佐尔卡
使用汇总函数MAX
SELECT names, MAX(score_round_1) GROUP BY round_1
SELECT *
FROM table p1
WHERE score_round_1 = (
SELECT MAX( p2.score_round_1 )
FROM table p2
WHERE p1.round_1 = p2.round_1 ) ANDround_1 !=0
This is simple 这很简单
select max(score_round_1),
name
from score
group by round_1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.