View Single Post
Old 09-19-2012, 11:44 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You know, looking at all those views, I think I see the problem in my original query.

I think it is missing the SELECT * that I have in the allresults VIEW.

So maybe this is all that needs added:
Code:
SELECT team.TeamID, team.teamName, allresults.wintotal, allresults.individualWins
FROM team
LEFT JOIN ( 
     SELECT * FROM
     ( SELECT rTeamID, SUM( IF(wld='w', 2, IF(wld='d', 1, 0 ) ) ) AS wintotal
       FROM results
       GROUP BY rTeamID ) AS tr
     INNER JOIN 
     ( SELECT x.iTeamID, COUNT(*) AS individualWins
       FROM (
              SELECT iTeamID FROM individResults WHERE fa='f'
              UNION ALL 
              SELECT iTeamID FROM individResultsDoubles WHERE fa='f'
            ) AS x
       GROUP BY x.iTeamID
     ) AS ir
     ON tr.rTeamID = ir.iTeamID
   ) AS allresults
ON team.teamID = allresults.rTeamID
ORDER BY allresults.wintotal, allresults.individualWins
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
gbarrett (09-20-2012)