I have a database that looks pretty much like this:
我有一个看起来非常像这样的数据库:
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的投票,并从最高开始订购它们。我希望输出如下:
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