koshi
Starting Member
1 Post |
Posted - 2015-03-01 : 17:13:10
|
Hi, I'm new here and I have very little knowledge of SQL.I was searching for a SQL query to calculate a soccer tableSo I found it at https://jonlabelle.com/snippets/view/sql/league-table-in-mysql. The query works fine, only when I add games for the future then he calculate them as played. How can I fix this?Thx for your help.SELECT tname 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 PtsFROM( SELECT hteam Team, 1 P, IF(hscore > ascore,1,0) W, IF(hscore = ascore,1,0) D, IF(hscore < ascore,1,0) L, hscore F, ascore A, hscore-ascore GD, CASE WHEN hscore > ascore THEN 3 WHEN hscore = ascore THEN 1 ELSE 0 END PTS FROM games UNION ALL SELECT ateam, 1, IF(hscore < ascore,1,0), IF(hscore = ascore,1,0), IF(hscore > ascore,1,0), ascore, hscore, ascore-hscore GD, CASE WHEN hscore < ascore THEN 3 WHEN hscore = ascore THEN 1 ELSE 0 END FROM games) as totJOIN teams t ON tot.Team=t.idGROUP BY TeamORDER BY SUM(Pts) DESC ; |
|