I've been hammering on this for a few day but can't get out of it, and am about to call it quits and just create a new table wich holds the results needed...
Maybe one of you smart and more experienced people can find a solution?
I have one table with game results (1bb), and one table containing teamnames (teams).
The first table has the fields Home, Away, HScore (HomeScore) and AScore (AwayScore).
The second table has the fields id and name.
What i want to do is create a ranking based on games played, amount won, draw and lost and order that by a win average.
the query should return the following for each teamid and order by average,games_played:
- name:
name of the team as found in table teams
- games_played:
count all rows where 1bb.Home or 1bb.Away = teamid and HScore != null
- amount_won:
if Home = teamid and HScore > Ascore then amount_won + 1
if Away = teamid and HScore < Ascore then amount_won + 1
- amount_draw:
if Home or Away = teamid and HScore=Ascore and HScore != null then amount_draw +1
- amount_lost:
games_played - (amount_won + amount_draw) = amount_lost
- average:
(amount_won+(amount_draw/2))/amount_played