I am unable to find the prop开发者_运维知识库er 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.
For example:
ID | ....
================
1 | ....
2 | ....
2 | ....
2 | ....
3 | ....
3 | ....
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
SELECT MAX(MAX_COUNT) FROM (SELECT COUNT(COLUMN_NAME) AS MAX_COUNT FROM TABLE_NAME GROUP BY COLUMN_NAME)
精彩评论