Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT title AS Team,SUM(P) AS P,SUM(W) AS W,SUM(D) AS D,SUM(L) AS L,SUM(F) AS F,SUM(A) AS A,SUM(GD) AS GD,SUM(Pts) AS Pts FROM (
- SELECT club_home AS Team,
- 1 P,
- IF(result_home > result_away,1,0) W,
- IF(result_home = result_away,1,0) D,
- IF(result_home < result_away,1,0) L,
- result_home F,
- result_away A,
- result_home-result_away GD,
- CASE WHEN result_home > result_away THEN 3 WHEN result_home = result_away THEN 1 ELSE 0 END PTS
- FROM matches
- WHERE result_home < 99 AND result_away < 99
- UNION ALL
- SELECT
- club_away,
- 1,
- IF(result_home < result_away,1,0),
- IF(result_home = result_away,1,0),
- IF(result_home > result_away,1,0),
- result_away,
- result_home,
- result_away-result_home GD,
- CASE WHEN result_home < result_away THEN 3 WHEN result_home = result_away THEN 1 ELSE 0 END
- FROM matches
- WHERE result_home < 99 AND result_away < 99
- ) AS tot JOIN clubs c ON tot.Team = c.id WHERE c.league_id = 14 GROUP BY Team ORDER BY SUM(Pts) DESC, GD DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement