Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. Team W L T PF PA PCT
  2. —————————————————————————————————
  3. Team1 7 3 0 247 139 0.7000
  4. Team2 6 2 2 220 122 0.6000
  5. Team3 6 4 0 191 191 0.6000
  6. Team4 4 5 1 167 201 0.4000
  7. Team5 3 6 1 142 202 0.3000
  8. Team6 2 8 0 193 305 0.2000
  9.  
  10. $result = mysql_query("
  11. SELECT team
  12. , COUNT(*) played
  13. , SUM(win) wins
  14. , SUM(loss) lost
  15. , SUM(win)/count(*) pctWon
  16. , SUM(draw) draws
  17. , SUM(SelfScore) ptsfor
  18. , SUM(OpponentScore) ptsagainst
  19. , SUM(SelfScore) - SUM(OpponentScore) goal_diff
  20. , SUM(3*win + draw) score
  21. FROM (
  22. SELECT team
  23. , SelfScore
  24. , OpponentScore
  25. , SelfScore > OpponentScore win
  26. , SelfScore < OpponentScore loss
  27. , SelfScore = OpponentScore draw
  28. FROM (
  29. SELECT HomeTeam team, HomeScore SelfScore, AwayScore OpponentScore
  30. FROM Game
  31. union all select AwayTeam, AwayScore, HomeScore
  32. FROM Game
  33. ) a
  34. ) b
  35. GROUP BY team
  36. ORDER BY wins DESC, draws DESC, lost ASC, goal_diff DESC;
  37. ");
  38.  
  39. echo "<table border='1'>
  40. <tr>
  41. <th>Team</th>
  42. <th>W</th>
  43. <th>L</th>
  44. <th>T</th>
  45. <th>PF</th>
  46. <th>PA</th>
  47. <th>PCT</th>
  48. </tr>";
  49.  
  50. while($row = mysql_fetch_assoc($result))
  51. {
  52. echo "<tr>";
  53. echo "<td>" . $row['team'] . "</td>";
  54. echo "<td>" . $row['wins'] . "</td>";
  55. echo "<td>" . $row['lost'] . "</td>";
  56. echo "<td>" . $row['draws'] . "</td>";
  57. echo "<td>" . $row['ptsfor'] . "</td>";
  58. echo "<td>" . $row['ptsagainst'] . "</td>";
  59. echo "<td>" . $row['pctWon'] . "</td>";
  60. echo "</tr>";
  61. }
  62. echo "</table>";
  63.  
  64. ORDER BY wins DESC, draws DESC, lost ASC, goal_diff DESC;
  65.  
  66. ORDER BY (wins*2 + draws) DESC, lost ASC, goal_diff DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement