select
steamid, name, sum(kills) as kills, sum(deaths) as deaths,
points, achievementPoints, speedrunPoints,
sum(wins) as wins, sum(losses) as losses, maxWonDiff
from
usernames
natural join
playerstats
natural left join
(select
steamid, max(difficulty) as maxWonDiff
from
playerstats
where
wins >= 1
group by
steamid
) as maxWonTable
natural join
(select
steamid,
sum(winpoints) + sum(achievementPoints) + sum(speedrunPoints) as points,
sum(winPoints) as winPoints,
sum(achievementPoints) as achievementPoints,
sum(speedrunPoints) as speedrunPoints
from
(SELECT steamid, difficulty, IFNULL(winpoints, 0) as winpoints, IFNULL(achievementPoints, 0) as achievementPoints, IFNULL(speedrunPoints, 0) as speedrunPoints
FROM (SELECT steamid, difficulty, sum(wins * ((difficulty - 2) * 3 - 2)) as winpoints from playerstats group by steamid, difficulty) AS winPoints natural left join (SELECT steamid, difficulty, sum((difficulty - 2) * 3 - 2) * 3 as achievementPoints from achievements group by steamid, difficulty) AS achievementPoints natural left join (SELECT steamid, difficulty, COUNT(*)*21 AS speedrunPoints
FROM bitemp.playerTimesMin NATURAL JOIN bitemp.mapTimesMin
GROUP BY steamid, difficulty
) as speedrunPoints )
AS FUNC_viewPoints
where
(0 <= 0 or difficulty = 0)
and
('STEAM_1:1:12304225' = '' or steamid = 'STEAM_1:1:12304225')
group by
steamid
) as pointsTable
where
(0 <= 0 or difficulty = 0)
and
('STEAM_1:1:12304225' = '' or steamid = 'STEAM_1:1:12304225')
group by
steamid
order by
points desc, wins desc, losses
limit
20

Got a packet bigger than 'max_allowed_packet' bytes

Got a packet bigger than 'max_allowed_packet' bytes