Player


SUBMITTED BY: Guest

DATE: Nov. 10, 2013, 3:20 p.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 12814

  1. +------------+--------+--------+
  2. | tournament | player | Points |
  3. +------------+--------+--------+
  4. | 1 | Bob | 9 |
  5. | 1 | Jeff | 2 |
  6. | 1 | Steve | 1 |
  7. | 2 | Bob | 5 |
  8. | 2 | Jeff | 3 |
  9. | 2 | Steve | 8 |
  10. | 2 | Paul | 4 |
  11. | 3 | Bob | 9 |
  12. | 3 | Jeff | 3 |
  13. | 3 | Steve | 2 |
  14. +------------+--------+--------+
  15. Bob: 2
  16. Steve: 1
  17. Jeff: 0
  18. Paul: 0
  19. select /*3. and finally we left join the original table to get all names and display the number of wins again*/
  20. outerq.player,
  21. coalesce(subq.wins, 0) as wins
  22. from
  23. Table1 outerq
  24. left join (
  25. select /*2. Now we determine how much tournaments each player won*/
  26. ot.player,
  27. count(*) as wins
  28. from (
  29. select /*1. First we determine the winners per tournament here*/
  30. *
  31. from
  32. Table1 t
  33. where Points = (select max(Points) from Table1 st where st.tournament = t.tournament)
  34. ) ot
  35. group by ot.player
  36. ) subq on outerq.player = subq.player
  37. group by outerq.player
  38. order by wins desc

comments powered by Disqus