一尘不染

在“ SQL”列中查找最频繁的值

mysql

如何在SQL表的给定列中找到最频繁的值?

例如,对于该表,它应该返回,two因为它是最频繁的值:

one
two
two
three

阅读 288

收藏
2020-05-17

共1个答案

一尘不染

SELECT       `column`,
             COUNT(`column`) AS `value_occurrence` 
    FROM     `my_table`
    GROUP BY `column`
    ORDER BY `value_occurrence` DESC
    LIMIT    1;

替换columnmy_table1如果要查看列的N最常用值,请增加。

2020-05-17