MySQL row values โ€‹โ€‹count WHERE column = value

I have a database that looks something like this:

enter image description here

I want to make a MySQL query where I count the votes for each id and order them starting from the highest. I want the result to be as follows:

enter image description here

Is this possible if you do not make 3 requests inside each other?

+6
source share
1 answer
select name, sum(votes) as total_votes from mytable group by 1 order by 2 desc 
+16
source

Source: https://habr.com/ru/post/945383/


All Articles