Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. SELECT p.team_name,final_table.Score
  2. from TEAMS p,
  3. (
  4. SELECT team.teamid TeamId,sum(team.Score) Score
  5. from(
  6. (SELECT home.team1_id TeamId,sum(home.Score) Score
  7. from(
  8. select team1_id,
  9. case
  10. WHEN goals_team1 > goals_team2 THEN 3
  11. WHEN goals_team1 = goals_team2 THEN 1
  12. ELSE 0
  13. END Score
  14. from RESULTS
  15. )home
  16. group by home.team1_id)
  17. union all
  18. (SELECT away.team2_id TeamId,sum(away.Score) Score
  19. from(
  20. select team2_id,
  21. case
  22. WHEN goals_team2 > goals_team1 THEN 3
  23. WHEN goals_team2 = goals_team1 THEN 1
  24. ELSE 0
  25.  
  26. END Score
  27. from RESULTS
  28. )away
  29. group by away.team2_id)) team
  30. group by team.teamid
  31. order by Score desc
  32. )final_table
  33. where p.team_id = final_table.teamid
  34. order by Score desc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement