count top 10 most occuring values in a column in mysql

前端 未结 4 1139
栀梦
栀梦 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:49

    Try:

    SELECT ColName, Count(1) AS occurances
        FROM
            table
        GROUP BY
            ColName
        ORDER BY
            occurances DESC
        LIMIT
            10
    
    0 讨论(0)
  • 2020-12-01 15:51

    Try the following code

    SELECT colname, COUNT(*) AS cnt
    FROM tablename
    GROUP BY colname
    ORDER BY cnt DESC
    LIMIT 10
    
    0 讨论(0)
  • 2020-12-01 15:52
    SELECT col, count(*)
        FROM tablethingie
        GROUP BY col
        ORDER BY count(*) DESC
        LIMIT 10
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题