2012-07-30 57 views
0

試圖選擇除自己以外的家族中的玩家總分數來確定你的氏族排名。mysql獲取加總行數

它返回的行數(大於你的氏族分數)是你的氏族位置。如果它返回3行,那麼你的氏族是第四位。

我的SQL(不工作):

SELECT sum(score) as sum_score 
FROM players WHERE sum_score > " .$our_clan_score . " 
AND clan !=0 AND clan != $our clan 
GROUP BY clan 

players

id name score clan 
------------------------------ 
4  Bill 455  2 

回答

3

可能是(不能老是檢查)

SELECT sum(score) as sum_score 
FROM players WHERE clan !=0 AND clan != ".$our_clan." 
GROUP BY clan 
HAVING sum_score > " .$our_clan_score . " 
+0

正常工作,謝謝 – user1022585 2012-07-30 16:50:06