Php 如何列出重复最多的前10行?
我想从下表中获取重复最多的前10行:Php 如何列出重复最多的前10行?,php,mysql,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实现这
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实现这一点(如果可能)
谢谢为什么要按所有列计数,为什么要运行count x2?您只需分配它,
vote,count(vote)as count
然后ORDER BY count
@Robert-它不会“运行count
两次”如果vote列中有空值,您的查询将不会输出正确的结果。@RobertPitt:他没有计算vote列中的值的数量,但投票列中具有相同值的行数。
select vote,count(vote) from votes group by vote order by count(vote) desc limit 10
select vote, count(*)
from votes
group by 1
order by 2 desc
limit 10