php - Sorting mysql results by several columns -
i'm building tournament system , need sort teams depending on 2 criteria:
- points (2 points winning series of 3 games)
- 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:
- get data db (sorted points)
- count number of occurrences of each points value (example: 9pts.x2, 7pts.x5...)
- make number of arrays needed according step 2.
- sort data these arrays, again depending on points value.
- if length of array longer 1, sort on difference between games won , games lost.
- 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
Comments
Post a Comment