php - Sorting mysql results by several columns -


i'm building tournament system , need sort teams depending on 2 criteria:

  1. points (2 points winning series of 3 games)
  2. difference in games (games won - lost)

now have 1 table column points, 1 individual games won , 1 individual games lost.

i results database sorted points (order points desc). problem comes individual rankings. if team , team b has same amount of points, team b has higher, positive, difference between games won , games lost, team b ranked higher team a.

since games won't played same time, , teams might behind on schedule, possible scenario 1 team having more wins other worse difference.

now solution i've been able come following:

  1. get data db (sorted points)
  2. count number of occurrences of each points value (example: 9pts.x2, 7pts.x5...)
  3. make number of arrays needed according step 2.
  4. sort data these arrays, again depending on points value.
  5. if length of array longer 1, sort on difference between games won , games lost.
  6. print end result.

this seems inefficient me. better ideas?

this work:

select name, wins, losses, points, (wins - losses) "diff" teams order points desc, diff desc 

demo: http://sqlfiddle.com/#!2/4ea97/1


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -