Anyone out there who could help me with this? Im looking to create an online football league generator. Alls going swimmingly until I go to create the actual league tables. I have this SQL so far.
SELECT user_id, SUM(points) AS pts, SUM(goals_for) AS gf, SUM(goals_against) AS ga FROM league_results INNER JOIN league_fixtures ON league_results.fixture_id = league_fixtures.id GROUP BY user_id
returns me all the info such as points, GF, GA etc. But I cannot figure out how to do the wins, losses, draws. there is a field in league_results called "points" which contains 3 (win), 1 (draw), or 0 (loss), so I'm making it really easy on my self. Im assuming its a subselect, but Im a bit naff at those. In pseudo code it would be something like
SELECT user, points, goals_for, goals_against, (SELECT count(points = 3) AS wins), (SELECT count(points = 1) AS draws), (SELECT count(points = 0) AS losses FROM ....
See what Im getting at? Any ideas?