Suppose I have a GAME table with the following fields
GAME
user_id, result
I wish to calculate win percentage defined as total numb
In MySQL, you can use this shortcut:
SELECT user_id, avg(Result = 'Win') AS WinPercent FROM Game GROUP BY user_id ORDER BY WinPercent DESC
Assuming Result is never NULL (empty string is ok). Otherwise you have to use Result IS NOT NULL AND Result = 'Win'