开发者

Count maximum times record appears in Database table

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜