开发者

How do I execute this query in MYSQL?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜