MySQL在同一列中选择多个/所有最大值 [英] MySQL SELECT multiple/all max values in the same column
本文介绍了MySQL在同一列中选择多个/所有最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我得到这张表:
MyTable
+----+-------+
| ID | count |
+----+-------+
| a | 2 |
| b | 6 |
| c | 4 |
| d | 6 |
| e | 2 |
+----+-------+
现在我想要这个:
Result
+----+-------+
| ID | count |
+----+-------+
| b | 6 |
| d | 6 |
+----+-------+
我想要具有最多计数值的 ID.所以如果有多个最大值,我想要它们.另外我不知道是否会有多个值,如果有,会有多少个.
I want the IDs that have the most counted values. So if there are multiple maximum values, I want them all. Also I don't know if there will be multiple values and if there are, how many it will be.
推荐答案
可以在子查询中获取最大的值.例如,
You can get the greatest value inside the subquery. Eg,
SELECT *
FROM MyTable
WHERE count =
(
SELECT MAX(count)
FROM MyTable
)
这篇关于MySQL在同一列中选择多个/所有最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文