开发者

How do I execute this query in MYSQL?

开发者 https://www.devze.com 2022-12-23 02:28 出处:网络
Suppose I have a column with words: orange grape orange orang开发者_如何学Ce apple orange grape banana How do I execute a query to get the top 10 words, as well as their count?SELECT word, COUNT(*)

Suppose I have a column with words:

orange
grape
orange
orang开发者_如何学Ce
apple
orange
grape
banana

How do I execute a query to get the top 10 words, as well as their count?


SELECT word, COUNT(*) word_cnt
FROM your_table
GROUP BY word
ORDER BY COUNT(*) DESC
LIMIT 10

The GROUP BY groups by values of word, the ORDER BY COUNT(*) DESC gets you the rows with highest count first, and the LIMIT 10 returns the first 10 rows only.


SELECT   word, COUNT(*) AS n
FROM     `table`
GROUP BY word
ORDER BY COUNT(*) DESC
LIMIT 10
0

精彩评论

暂无评论...
验证码 换一张
取 消