How to execute this query in MYSQL?

Suppose I have a column with the words:

orange
grape
orange
orange
apple
orange
grape
banana

How to fulfill the request to get the top 10 words, as well as their score?

+3
source share
2 answers
SELECT word, COUNT(*) word_cnt
FROM your_table
GROUP BY word
ORDER BY COUNT(*) DESC
LIMIT 10

Groups GROUP BYby values word, ORDER BY COUNT(*) DESCfirst get the rows with the highest number, and LIMIT 10returns only the first 10 rows.

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

Source: https://habr.com/ru/post/1736954/


All Articles