I would appreciate some help with the following
SELECT distinct playerid as le_player,
(select sum(score) from playerresults where playerid = le_player) as wins,
(select handicap from players where playerid = le_player) as handicap, playername,
(select count(playerid)*3 from playerresults where playerid = le_player)as totalgames,
(select count(playerid)*3 from playerresults where playerid = le_player) - (select sum(score) from playerresults where playerid = le_player)as lost,
round((select sum(score) from playerresults where playerid = le_player) / (select count(playerid)*3 from playerresults where playerid = le_player) * 100,2) as percent,
teams.team_name
FROM playerresults
INNER JOIN teams on (select players.team_id from players where players.id = playerid) = teams.id
WHERE playerresults.season = 2012 AND playerresults.league = 4
ORDER BY wins desc,totalgames asc
It was working until I added the following line:
(select handicap from players where playerid = le_player) as handicap
This now produces a Subquery returns more than 1 row error.
Handicap was a new field added to my players table so I thought I could just add that bit of sql to my original.
Any thoughts?
Thanks
dg
You might want to consider using joins with the tables instead of all of the correlated subqueries:
Or even something like this: