问题
`id` int(11) NOT NULL,
`ip` text NOT NULL,
`song` text NOT NULL,
`vote` int(11) NOT NULL
I have created a voting system and I would like to print the songs with more votes ... how do I do it? Thank you
回答1:
I think you need to try for counting total votes for the song
SELECT SUM(vote)as VOTECOUNT, song FROM votes GROUP BY song ORDER BY SUM(vote) DESC LIMIT 10
回答2:
If I understand correctly your table contains each single vote. I also assume that song is unique ID of a song. If that is so you need to sum the values of vote and divide it to the total votes.
SELECT song, SUM(vote)/COUNT(*) AS rateing FROM your_table_name GROUP BY song ORDER BY rateing DESC;
回答3:
You need to try below query.you can get higest voted songs. put your table name in 'table_name'.
SELECT song,SUM(vote)as VOTECOUNT FROM table_name GROUP BY song order by VOTECOUNT desc
来源:https://stackoverflow.com/questions/44964269/ranking-in-php-and-mysql