Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count top 10 most occuring values in a column in mysql

Tags:

mysql

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?

like image 922
mrpatg Avatar asked Dec 02 '09 08:12

mrpatg


People also ask

Can we use count in where clause in MySQL?

SQL SELECT COUNT() can be clubbed with SQL WHERE clause. Using the WHERE clause, we have access to restrict the data to be fed to the COUNT() function and SELECT statement through a condition.

How to count the top 10 most occurring values in MySQL?

To count the top 10 most occurring values in a column in MySQL, The syntax is as follows − To understand the above syntax, let us create a table. The query to create a table is as follows − Insert some records in the table using insert command. The query is as follows − Now you can Display all records from the table using select statement.

How to select top 10 most occurring values in a column?

The following is the query to select top 10 most occurring values in a column in MySQL − mysql> SELECT Value, count(*) -> FROM countTop10Demo -> GROUP BY Value -> ORDER BY count(*) DESC -> LIMIT 10; Here is the output −

How to get the N most frequent values from value_counts?

To get 5, 10 or N most frequent values in a single column we can use method value_counts: 5.50 4685 5.60 3967 5.70 3079 5.80 2346 5.90 1947 6.00 1580 .... Name: Magnitude, dtype: int64 To get the N most frequent values only without the count we can use: To get the single most frequent value from value_counts we can combine it with idmax:

How to rank the users by row count in a table?

This ranks the users by row count and returns the top row. Top User = FIRSTNONBLANK ( TOPN ( 1, VALUES ( UserTableName [UserColumnName] ), RANKX ( ALL ( UserTableName [UserColumnName] ), [Row Count],,ASC) ), 1 ) 05-04-2017 03:42 PM Hi Daemetius. So there's a way to do this using Top N, First Non Blank, and Rank X.


1 Answers

SELECT col, count(*)
    FROM tablethingie
    GROUP BY col
    ORDER BY count(*) DESC
    LIMIT 10
like image 63
Michael Krelin - hacker Avatar answered Sep 21 '22 17:09

Michael Krelin - hacker