delete from Scores
where playerName+'|'+cast(levelID as varchar)+'|'+cast(Difficulty as varchar)+'|'+cast(score as varchar)
in(
select playerName+'|'+cast(levelID as varchar)+'|'+cast(Difficulty as varchar)+'|'+cast(score as varchar) from
(Select rank() over (partition by cast(levelID as varchar)+'|'+cast(Difficulty as varchar) order by score desc) as bRank,*
from Scores as b) as Ranks
where Ranks.bRank >= 10)
可以更換playerName + '|' + CAST(levelID爲varchar)+ '|' |你的主鍵
+投(得分爲varchar)+投(難度爲varchar)+ ''
這會給你的球員在10日及以後的地方:
select Ranks.* from
(Select rank() over (partition by cast(levelID as varchar)+'|'+cast(Difficulty as varchar)
order by score desc) as bRank,*
from Scores as b) as Ranks
where Ranks.bRank >= 10
結果:
bRank playerName LevelID Score Difficulty
-------------------- -------------------------------------------------- ----------- ----------- -----------
10 Player 3 1 3 10
11 Player 2 1 2 10
12 Player 1 1 1 10
您正在使用的數據庫? MySQL的? – Andomar 2010-07-08 08:51:34
爲什麼不只是存儲所有的分數,並選擇前10名? 否則,觸發器應該做的工作 – BenW 2010-07-08 08:51:57
我使用SQLite – penpen 2010-07-08 09:04:03