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