def best_drivers(limit = 10)
lost = 'SELECT COUNT(c.id) FROM challenges AS c
WHERE (c.challenger_id = u.id AND c.challenge_state_id = 5)
OR (c.opponent_id = u.id AND c.challenge_state_id = 4)'
won = 'SELECT COUNT(c.id) FROM challenges AS c
WHERE (c.challenger_id = u.id AND c.challenge_state_id = 4)
OR (c.opponent_id = u.id AND c.challenge_state_id = 5)'
# WHERE statement prevents division by zero
find_by_sql(
'SELECT u.*, cast(('+won+') as float)/(cast(('+won+') as float)+cast(('+lost+') as float)) AS win_ratio, ('+won+') AS won, ('+lost+') AS lost
FROM users AS u
WHERE ('+won+') > 0
ORDER BY win_ratio DESC, won DESC
LIMIT '+limit.to_s
)
end
我正在使用此查詢排序排名表中的用戶,它工作正常。球員當前排名
現在我需要一個查詢來告訴我show view中用戶的當前排名。可能嗎?