Advertisement
alexarcan

l3_dbd

Oct 16th, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. insert into results values(1,2,2,0);
  2. insert into results values(1,3,2,1);
  3. insert into results values(2,1,1,1);
  4. insert into results values(2,3,1,0);
  5. insert into results values(3,1,0,1);
  6. insert into results values(3,2,1,1);
  7.  
  8.  
  9. create view MatchWon (team_id) as
  10. select team1_id from results
  11. where goals_team1>goals_team2
  12. union all
  13. select team2_id from results
  14. where goals_team1<goals_team2;
  15.  
  16. create view MatchEqual (team_id) as
  17. select team1_id from results
  18. where goals_team1=goals_team2
  19. union all
  20. select team2_id from results
  21. where goals_team1=goals_team2;
  22.  
  23. create view PointsWon(team_id, points) as
  24. select t.team_id, (count(w.team_id)*3) as points from teams t, matchwon w
  25. where t.team_id=w.team_id(+)
  26. group by t.team_id;
  27.  
  28. create view PointsEqual(team_id, points) as
  29. select t.team_id, count(e.team_id) as points from teams t, matchequal e
  30. where t.team_id=e.team_id(+)
  31. group by t.team_id;
  32.  
  33. create view PointsInit (team_id, won, equal) as
  34. select t.team_id, sum(w.points), sum(e.points) from teams t, pointswon w, pointsequal e
  35. where t.team_id=w.team_id and t.team_id=e.team_id
  36. group by t.team_id;
  37.  
  38. create view Rank(team_id, points) as
  39. select t.team_id, p.won+p.equal as points from teams t, pointsinit p
  40. where t.team_id=p.team_id
  41. order by points desc;
  42.  
  43. create view RankTeams (team_id, points) as
  44. select team_id, sum(points) as points from
  45. (
  46. select team1_id as team_id, decode(sign(goals_team1-goals_team2),1,3,0,1,-1,0) as points from results
  47. union all
  48. select team2_id as team_id, decode(sign(goals_team2-goals_team1),1,3,0,1,-1,0) as points from results
  49. ) pointsMatch
  50. group by team_id
  51. order by points desc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement