Log in

View Full Version : Only return top 5 records per category



GoKats78
10-11-2012, 02:49 AM
Here is the query..what I want to have returned is only the top 5 records (for each Sum([Placings & Points].Points) for each of the Awards.[SPHO-Ohio Approved Classes Awards]..

So what I have are about 25 separate awards...based on the sum of the points earned. And I need to return only the hihgest 5 total points for each of the awards



SELECT Awards.[SPHO-Ohio Approved Classes Awards], ) AS SumOfPoints, [2012 Points].Members
FROM (Awards INNER JOIN (Classes INNER JOIN (Events INNER JOIN [2012 Points] ON Events.ID = [2012 Points].[Show or Event]) ON Classes.ID = [2012 Points].Class) ON Awards.ID = Classes.[Award Division]) INNER JOIN [Placings & Points] ON [2012 Points].Placing = [Placings & Points].ID
WHERE (((Events.[SPHO Show])=-1))
GROUP BY Awards.[SPHO-Ohio Approved Classes Awards], [2012 Points].Members
ORDER BY Awards.[SPHO-Ohio Approved Classes Awards], Sum([Placings & Points].Points) DESC;

GoKats78
10-11-2012, 04:26 PM
Can anyone help me out here?

mohanvijay
10-11-2012, 11:34 PM
Can you please post sample data and desired output in excel or access format?

orange
10-14-2012, 12:20 PM
see Top N per Group at
http://allenbrowne.com/subquery-01.html