Ranking in PHP and MySQL [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-25 17:37:29

问题


  `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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!