MySQL计数行值WHERE column = value

时间:2021-07-19 13:35:25

I have a database that looks pretty much like this:

我有一个看起来非常像这样的数据库:

MySQL计数行值WHERE column = value

I wanna make a MySQL query where I count the votes for each id and order them by starting from the highest. I want the output to be like:

我想做一个MySQL查询,我计算每个id的投票,并从最高开始订购它们。我希望输出如下:

MySQL计数行值WHERE column = value

Is it possible without making like 3 queries inside each other?

是不是可以在彼此内部进行3次查询?

1 个解决方案

#1


17  

select
    name,
    sum(votes) as total_votes
from mytable
group by 1
order by 2 desc

#1


17  

select
    name,
    sum(votes) as total_votes
from mytable
group by 1
order by 2 desc