I've developing an online game where people can come first - fourth in each game, and I want a league table showing the people with the highest percentage of 1sts for all the games they've played.
This is the MySQL query I've got at the moment, but it's taking ~16 seconds and it's still in private testing with about 400 tables (a table = a game), so when it [hopefully] become the most popular game ever, it'll have 1,000s of games to work with and it'll take forever.
Is there a more efficient way to do this?
I also have a table linking each player to each game that I could use to count the games, but I thought joining another table could be more resource intensive, but does each subquery use more resources?
I also have a test player who's won 133% of the game, but I think this is just because of anomalous data before the system was working right, or is this query just not right?
Thank you 🙂
This is the MySQL query I've got at the moment, but it's taking ~16 seconds and it's still in private testing with about 400 tables (a table = a game), so when it [hopefully] become the most popular game ever, it'll have 1,000s of games to work with and it'll take forever.
Is there a more efficient way to do this?
Code:
SELECT (
(SELECT COUNT(*) FROM tables WHERE first=players.playerID GROUP BY first) /
(SELECT COUNT(*) FROM tables WHERE status='finished' and
(first=players.playerID or second=players.playerID or third=players.playerID or fourth=players.playerID) GROUP BY playerID)
*100) as first_percentage, userName
FROM tables JOIN players WHERE 1=1 GROUP BY playerID
ORDER BY first_percentage DESC LIMIT 10
I also have a table linking each player to each game that I could use to count the games, but I thought joining another table could be more resource intensive, but does each subquery use more resources?
I also have a test player who's won 133% of the game, but I think this is just because of anomalous data before the system was working right, or is this query just not right?
Thank you 🙂