MySQL SELECT query to create ladder in sports competition -


i trying create sports fixture , ladder sports competition. having trouble creating ladder.

i ladder this. teams 2 points win or bye , 1 point draw.

and create ladder using table looks this

this far have gotten, returns names of teams have won game , how many games have won:

select teamname,count(*) wins  result pointsfor > pointsagainst , completed = "1"  group teamname order wins desc; 

try using subqueries this:

select     teamname,     (select count(*) result teamname = r.teamname , pointsfor > pointsagainst , completed = 1) wins,     (select count(*) result teamname = r.teamname , pointsfor < pointsagainst , completed = 1) losses,     (select count(*) result teamname = r.teamname , pointsfor = pointsagainst , completed = 1) draws result r group teamname order wins desc 

edit: added group by


Comments