我正在为我们的社交飞镖俱乐部创建排行榜系统。我有一个MySQL数据库,其中包含玩家姓名及其分数
示例:
Name Date Place Points
John 11-01-2015 1st 10
Anthony 12-01-2015 1st 10
Andre 13-01-2015 1st 10
John 14-01-2015 1st 10
我需要为每个玩家遍历表格,计算总积分并输出排行榜风格
最佳数据库结果
Name Points
John 20
Andre 10
Anthony 10
答案 0 :(得分:0)
SELECT name, SUM(points) AS points
FROM table1
GROUP BY name
ORDER BY 2 DESC;
构建GROUP BY并按SUM列命令desc。
也许您需要一些过滤器位置
SELECT name, SUM(points) AS points
FROM table1
WHERE place = '1st'
GROUP BY name
ORDER BY 2 DESC;