TCARPENTER
Programmer
I have two tables, one with the school name and the other with the events, athletes, and their scores. The top 4 scores are the ones that count towards the total.
What's wrong with my query - it's not returning correct number:
Bars
7.1
0
6.325
5.475
0
6.425
These values should return 25. but it's returning 11.9 - I thought TOP returned the highest values...?
Thanks for any help.
What's wrong with my query - it's not returning correct number:
Code:
SELECT Schools.Name, Sum(Scores.Bars) AS TopOfBars, Sum(Scores.Beam) AS TopOfBeam, Sum(Scores.Floor) AS TopOfFloor, Sum(Scores.Vault) AS TopOfVault, [TopOfBars]+[TopOfBeam]+[TopOfFloor]+[TopOfVault] AS Totals
FROM Schools INNER JOIN Scores ON Schools.ID = Scores.School
WHERE (((Scores.Bars) In (SELECT TOP 4 Bars from Scores WHERE Id = Scores.School ORDER BY Bars DESC)) AND ((Scores.Beam) In (SELECT TOP 4 Beam from Scores WHERE Id = Scores.School ORDER BY Beam DESC)) AND ((Scores.Floor) In (SELECT TOP 4 Floor from Scores WHERE Id = Scores.School ORDER BY Floor DESC)) AND ((Scores.Vault) In (SELECT TOP 4 Vault from Scores WHERE Id = Scores.School ORDER BY Vault DESC)))
GROUP BY Schools.Name
ORDER BY Schools.Name;
Bars
7.1
0
6.325
5.475
0
6.425
These values should return 25. but it's returning 11.9 - I thought TOP returned the highest values...?
Thanks for any help.