Invalid query dude : select gsOpp, ttTecmoOrder, ttName, ttCity, sum(gsAttempts) as passes, sum(gsPassYards) as passyds, sum(gsPassTDs) as passtds, sum(gsRushes) as rushes, sum(gsRushYards) as rushyds, sum(gsRushTDs) as rushtds, (sum(gsPassYards)+sum(gsRushYards)) as total, sum(gsRushYards)/COUNT(DISTINCT(gsgUID)) as rushydsavg, sum(gsPassYards)/COUNT(DISTINCT(gsgUID)) as passydsavg, ((sum(gsPassYards)+sum(gsRushYards))/COUNT(DISTINCT(gsgUID))) as totalavg , tttID from standings, game_stats where gsOpp = tttID AND ttlUID = 1 AND ttlUID = gslUID AND gsSeason = 2010 AND gsSeason = ttsUID AND gsWeek <= 20 group by tttID order by desc, totalavg asc, passyds asc, rushyds asc