Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何列出重复最多的前10行?_Php_Mysql - Fatal编程技术网

Php 如何列出重复最多的前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实现这

我想从下表中获取重复最多的前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实现这一点(如果可能)


谢谢

为什么要按所有列计数,为什么要运行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