在"SQL"列中查找最频繁的值 [英] Find most frequent value in SQL column
本文介绍了在"SQL"列中查找最频繁的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在SQL表的给定列中找到最频繁的值?
How can I find the most frequent value in a given column in an SQL table?
例如,对于此表,它应该返回two
,因为它是最常用的值:
For example, for this table it should return two
since it is the most frequent value:
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
.如果要查看列的N
最常用值,请增加1
.
Replace column
and my_table
. Increase 1
if you want to see the N
most common values of the column.
这篇关于在"SQL"列中查找最频繁的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文