假设我有一个包含单词的列:
orange
grape
orange
orange
apple
orange
grape
banana
如何执行查询以获取前10个单词及其计数?
答案 0 :(得分:3)
SELECT word, COUNT(*) word_cnt
FROM your_table
GROUP BY word
ORDER BY COUNT(*) DESC
LIMIT 10
GROUP BY
组的值word
,ORDER BY COUNT(*) DESC
获取最先计数最多的行,LIMIT 10
仅返回前10行。
答案 1 :(得分:3)
SELECT word, COUNT(*) AS n
FROM `table`
GROUP BY word
ORDER BY COUNT(*) DESC
LIMIT 10