Advertisement
Puzo

SQL - nkralj

Sep 5th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.18 KB | None | 0 0
  1. 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 (
  2.         SELECT club_home AS Team,  
  3.         1 P,  
  4.         IF(result_home > result_away,1,0) W,
  5.         IF(result_home = result_away,1,0) D,
  6.         IF(result_home < result_away,1,0) L,
  7.         result_home F,
  8.         result_away A,
  9.         result_home-result_away GD,
  10.         CASE WHEN result_home > result_away THEN 3 WHEN result_home = result_away THEN 1 ELSE 0 END PTS
  11.         FROM matches
  12.         WHERE result_home < 99 AND result_away < 99
  13.          
  14.         UNION ALL
  15.         SELECT
  16.         club_away,  
  17.         1,  
  18.         IF(result_home < result_away,1,0),
  19.         IF(result_home = result_away,1,0),  
  20.         IF(result_home > result_away,1,0),  
  21.             result_away,  
  22.         result_home,  
  23.         result_away-result_home GD,  
  24.         CASE WHEN result_home < result_away THEN 3 WHEN result_home = result_away THEN 1 ELSE 0 END  
  25.         FROM matches
  26.         WHERE result_home < 99 AND result_away < 99
  27.         ) 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