Ver originalSELECT t.id, t.nome AS Equipo , (SUM(CASE WHEN (g.hometeam = t.id AND g.homegoals > g.awaygoals ) OR ( g.awayteam = t.id AND g.awaygoals > g.homegoals) THEN 3 ELSE 0 END) + SUM(CASE WHEN ( g.hometeam = t.id OR g.awayteam = t.id ) AND ( g.homegoals = g.awaygoals ) THEN 1 ELSE 0 END)) AS PTS , SUM(CASE WHEN ( g.hometeam = t.id OR g.awayteam = t.id ) THEN 1 ELSE 0 END) AS PJ , SUM(CASE WHEN ( g.hometeam = t.id AND g.homegoals > g.awaygoals ) OR ( g.awayteam = t.id AND g.awaygoals > g.homegoals ) THEN 1 ELSE 0 END) AS V , SUM(CASE WHEN ( g.hometeam = t.id OR g.awayteam = t.id ) AND g.homegoals = g.awaygoals THEN 1 ELSE 0 END) AS E , SUM(CASE WHEN ( g.hometeam = t.id AND g.homegoals < g.awaygoals ) OR ( g.awayteam = t.id AND g.awaygoals < g.homegoals ) THEN 1 ELSE 0 END) AS D , COALESCE(SUM(CASE WHEN (g.hometeam = t.id) THEN g.homegoals WHEN (g.awayteam = t.id) THEN g.awaygoals END),0) AS GF , COALESCE(SUM(CASE WHEN (g.hometeam = t.id) THEN g.awaygoals WHEN (g.awayteam = t.id) THEN g.homegoals END),0) AS GC , COALESCE((SUM(CASE WHEN (g.hometeam = t.id) THEN g.homegoals WHEN (g.awayteam = t.id) THEN g.awaygoals END) - SUM(CASE WHEN (g.hometeam = t.id) THEN g.awaygoals WHEN (g.awayteam = t.id) THEN g.homegoals END)),0) AS DIF FROM teams t LEFT OUTER JOIN games g ON t.id IN (g.hometeam,g.awayteam) WHERE g.torneo_id = '1' AND g.homegoals <> '' GROUP BY t.id, t.nome ORDER BY PTS DESC, V DESC, DIF DESC, GF DESC, PJ ASC, t.nome ASC