Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Old chestnut, ranking query 1

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
GB
Sorry to have to ask this as it's a frequent subject but I'm struggling to add ranking by Total for each Company in each Category in this query.

EXAPoints_jgub8p.jpg


What I want is this, etc
Rank_eexmxx.jpg


Using other posts I've tried this SQL, amongst others, but am not getting what I want.

Code:
SELECT s1.Category, s1.Company, s1.EntryID, s1.Judge, s1.Total, Count(s2.Total)+1 AS Rank
FROM qryPoints AS s1 INNER JOIN qryPoints AS s2 ON s1.EntryID = s2.EntryID
GROUP BY s1.Category, s1.Company, s1.EntryID, s1.Judge, s1.Total;

It just counts the number of Judges for each Company and adds 1.

Rank_Result_qs8aja.jpg
 
I would use a subquery like:

SQL:
SELECT qselTrekBiker.Category, qselTrekBiker.Company, qselTrekBiker.Judge, qselTrekBiker.Total, 
(Select Count(*) FROM qselTrekBiker B WHERE B.Category = qselTrekBiker.Category AND
  B.Company = qselTrekBiker.Company  and B.[Total] >=qselTrekbiker.[Total]) AS Rank
FROM qselTrekBiker
ORDER BY qselTrekBiker.Category, qselTrekBiker.Company, qselTrekBiker.Total DESC;


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
That's perfect, thanks Duane, your help is appreciated as ever. This database is full of references to help you have provided!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top