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