count top 10 most occuring values in a column in mysql

前端 未结 4 1167
栀梦
栀梦 2020-12-01 15:39

I have a column in mysql table that has the the data type INT(11).

How can I search to get the top 10 most occurring values in this column?

4条回答
  •  清歌不尽
    2020-12-01 15:52

    TOP is a keyword which is not supported in MySQL, it is in MSSQL though.

    This following query should do what you want (untested, but the idea should become clear):

    SELECT column, COUNT(*) AS matches 
    FROM table 
    GROUP BY column 
    ORDER BY matches DESC 
    LIMIT 10
    

提交回复
热议问题