SELECT mapdef.uniqueid AS mapname, SUM(( ABS( mapdata.ctwon / (mapdata.ctwon + mapdata.terroristwon) - (mapdata.terroristwon / (mapdata.ctwon + mapdata.terroristwon)) ) * IF ( mapdata.ctwon / (mapdata.ctwon + mapdata.terroristwon) > mapdata.terroristwon / (mapdata.ctwon + mapdata.terroristwon), (stats.terroristwon + stats.terroristlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) - (stats.ctwon + stats.ctlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ), (stats.ctwon + stats.ctlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) - (stats.terroristwon + stats.terroristlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) ) ) * ( SELECT weight FROM ( SELECT @avg:= ( SELECT AVG(ctwon + ctlost + terroristwon + terroristlost) AS avg FROM ps_c_plr_maps WHERE plrid = 6 AND lastdate > DATE_SUB(NOW(), INTERVAL 14 DAY) ), mapid, CASE WHEN ((ctwon + ctlost + terroristwon + terroristlost) >= (@avg)) THEN 1 ELSE (ctwon + ctlost + terroristwon + terroristlost) / (@avg) END AS weight FROM ps_c_plr_maps WHERE plrid = 6 ) AS weight WHERE weight.mapid = stats.mapid )) AS teamratio FROM ps_c_plr_maps AS stats, ps_c_map_data AS mapdata, ps_map AS mapdef WHERE (stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost > 0) AND stats.plrid = 6 AND stats.mapid = mapdef.mapid AND mapdef.mapid IN ( SELECT DISTINCT mapid FROM ps_c_plr_maps WHERE lastdate > DATE_SUB(NOW(), INTERVAL 14 DAY) AND plrid = 6 ) AND mapdata.mapid = mapdef.mapid GROUP BY stats.plrid,mapdef.mapid ORDER BY teamratio +-------------------+-----------------+ | mapname | teamratio | +-------------------+-----------------+ | de_nightfever | -0.047217959062 | | de_tides | -0.011967652109 | | de_train | 0.000322773619 | | de_dust2 | 0.000356559951 | | de_nuke | 0.001638071506 | | de_cbble | 0.002155278530 | | de_losttemple_pro | 0.003046205440 | | de_inferno | 0.003815144037 | | de_chateau | 0.005592974531 | | de_prodigy | 0.011873021055 | | de_piranesi | 0.017991999965 | | cs_italy | 0.033892078123 | +-------------------+-----------------+ 12 rows in set (0.19 sec)