本文介绍了在 MySQL 中获得最高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的表格:
ID Score
1 90
2 85
3 96
4 96
5 73
我想获得最佳射手,所以我使用了 max 函数:
I want to get the top scorer(s) so I used max function:
select max(s.score) as score,
s.id
from student_score as s
结果:
score id
96 1
问题是,有两个最佳射手,我如何才能获得所有最佳射手?
The problem is, there are two top scorers, how am I going to get all top scorers?
推荐答案
子查询从表 student_score
中获取最大分数,结果将用于在 WHERE
上进行比较子句.
The subquery gets the maximum score from table student_score
which the result will be used to compare on WHERE
clause.
SELECT a.*
FROM student_score a
WHERE Score =
(
SELECT MAX(Score)
FROM student_score
)
- 查看 SQLFiddle 演示
这篇关于在 MySQL 中获得最高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!