mySQL query to find the most repeated value

后端 未结 2 1094
说谎
说谎 2020-12-08 12:03

I have a table with several rows, for each of them I need to know the most common value.

Example:

row_1 has

car
boat
car
car
truck
truck
plan         


        
2条回答
  •  庸人自扰
    2020-12-08 12:34

    I wrote the query in a way such that if there are more items with the same highest number of occurrences, you will see them all, not just one of them.

    select item
    from table
    group by item
    having count(item) = (
    select count(item) as great
    from table
    group by item order by great desc limit 1)
    

提交回复
热议问题