$$loop row as stat index as statindex select count(*) as killcount,id,playerteam,realname,image,(select count(*) from killdata as subkilldata where killdata.playerteam=subkilldata.playerteam and killtype='SUICIDE') as suicidecount,(select count(*) from killdata as subkilldata where killdata.playerteam=subkilldata.playerteam and killtype='TEAMKILL') as teamkillcount from killdata,team where killtype='KILL' and team.idx=killdata.playerteam group by playerteam order by killcount desc limit %%MAXMAINPAGETEAMS%%$$