我需要拿出一個結果,顯示前3名的結果,從每個球員,以及將和數對它進行排序從每個球員前3名的結果和排序總
示例表的總和:
David = 12 Mike = 17 John = 20 Bill = 20
David = 12 Mike = 16 John = 18 Bill = 20
David = 11 Mike = 15 John = 16
David = 10 Mike = 14 John = 16
David = 10 John = 15
結果需要顯示如下:
John = 54
Mike = 50
Bill = 40
David = 35
我已經到位排名爲所有事件(簡單):
SELECT playerName, SUM(`eventPoints`)
FROM `eventresults`
GROUP BY `playername`
ORDER BY SUM(`eventPoints`) DESC
我想做到以下幾點與PHP代碼:
- 創建一個表名爲top3Events在啓動
- 通過查詢的結果看了上面的表eventResults
- TRUNCATE top3Events
- 使用計數器並重置每個新玩家名稱
- INSERT INTO top3Events when counter < = 3
運行此查詢:
SELECT playerName, SUM(`eventPoints`)
FROM `top3Events`
GROUP BY `playername`
ORDER BY SUM(`eventPoints`) DESC
不知道這是去與此
什麼表結構?列 ? – 4EACH 2014-10-10 14:04:10
請格式化您的問題一下,之後我會刪除downvote – Miki 2014-10-10 14:05:59
爲簡單起見,列是playerName,eventPoints – David 2014-10-10 14:12:47