如何在SQL表的给定列中找到最频繁的值?
例如,对于该表,它应该返回,two因为它是最频繁的值:
two
one two two three
SELECT `column`, COUNT(`column`) AS `value_occurrence` FROM `my_table` GROUP BY `column` ORDER BY `value_occurrence` DESC LIMIT 1;
替换column和my_table。1如果要查看列的N最常用值,请增加。
column
my_table
1
N