计数最大次数记录出现在数据库表中 [英] Count maximum times record appears in Database table
本文介绍了计数最大次数记录出现在数据库表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法找到合适的mysql函数,但正在尝试查找单个记录相对于所有其他记录出现在数据库中的最大次数.
I am unable to find the proper mysql function but am trying to find the maximum number of a times a single record appears within a database relative to all other records.
例如:
ID | ....
================
1 | ....
2 | ....
2 | ....
2 | ....
3 | ....
3 | ....
我要实现的查询的理想返回值为3(计数1为1,计数2为3,计数3为2,因此返回ANY id的最大计数).
the ideal return for what query i am trying to achieve is 3 (the count of 1 is 1, count of 2 is 3, count of 3 is 2 so return maximum count of ANY id).
推荐答案
不能直接嵌套,否则将获得分组的最大值.嵌套选择.
Can't nest directly, otherwise you'll get a grouped max. Nest the selects instead.
select max(c) from (
select
count(*) c
group by
.. whatever ...
) x
这篇关于计数最大次数记录出现在数据库表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文