如何列出前10个最重复的行?

时间:2010-12-07 22:39:40

标签: php mysql

我想从下表中获取前10个最重复的行:

Table Name: votes(id,vote)
--------------------------
1 | Taylor Swift
2 | Maroon5
3 | Maroon5
4 | Maroon5
5 | Taylor Swift
6 | Kanye West

输出应该是这样的:

1. Maroon5: 3 votes
2. Taylor Swift: 2 votes
3. Kanye West: 1 votes

如何仅使用MySQL(如果可能)

谢谢

2 个答案:

答案 0 :(得分:8)

select vote, count(*)
from votes
group by 1
order by 2 desc
limit 10

答案 1 :(得分:1)

select vote,count(vote) from votes group by vote order by count(vote) desc limit 10