2012-07-30 105 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