Re: ranking calculated fields in a query



Steve,
I have simplified the number of fields so you can see how this will work,
then you can add in the extra fields.
I created 3 tables : tblTwirlers, tblFees, tblModellingXTab.
Make the following query and save it as qRank

SELECT tblTwirlers.FirstName, tblFees.Level, tblModellingXTab.R3,
tblModellingXTab.AgeGroup
FROM tblTwirlers INNER JOIN (tblFees INNER JOIN tblModellingXTab ON
tblFees.FeesID = tblModellingXTab.PageantID) ON tblTwirlers.TwirlerID =
tblModellingXTab.TwirlerID
ORDER BY tblFees.Level, tblModellingXTab.R3;

Then create the following query:

SELECT Q.FirstName, Q.AgeGroup, Q.R3, (SELECT COUNT(*) FROM qRank As Q1
WHERE Q1.[Agegroup] = Q.[Agegroup]
AND Q1.R3 <= Q.R3) AS Rank
FROM qRank AS Q
WHERE ((((SELECT COUNT(*) FROM qRank Q1
WHERE Q1.[Agegroup] = Q.[Agegroup]
AND Q1.R3 > Q.R3)+1)<>False))
ORDER BY Q.AgeGroup, Q.R3 DESC;

The result is:
FirstName AgeGroup R3 Rank
Jane 10 - 12 7 3
Sally 10 - 12 6 2
Mary 10 - 12 5 1
Sam 9 - 10 11 5
Pat 9 - 10 10 4
Sue 9 - 10 10 4
Jo 9 - 10 8 2
Beth 9 - 10 6 1



Jeanette Cunningham


"Steve S" <SteveS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E5AABF02-EA02-4416-AFA5-D9271A1FC11A@xxxxxxxxxxxxxxxx
the following select query adds 3 fields (R1 R2,R3) to create MPP. What I
need to do is add the code to Rank MPP within Level and Age Group. I have
tried several variations of code offered by others in responce to
questions
in this news group but evidently I lack the skill level to insert samples
into my existing code.

SELECT [Twirlers].[First Name] & " " & [Twirlers].[Last Name] AS Name,
Fees.Level, ModelingXTab.[Age Group], Val(nz([MJ1R],0)) AS R1,
Val(nz([MJ2R],0)) AS R2, Val(nz([MJ3R],0)) AS R3, [R1]+[R2]+[R3] AS MPP,
"Some SQL" AS Rank
FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.[Twirler ID] =
Twirlers.[Twirler ID]) INNER JOIN Fees ON ModelingXTab.[Pagent ID] =
Fees.[Fee ID];

the results of this query should look like:

Mary Advanced 10-12 2 2 1 5 1
Jane Advanced 10-12 3 1 3 7 3
Sally Advanced 10-12 1 3 2 6 2

Beth Advanced 9-10 1 3 2 6 1
Jo Advanced 9-10 2 1 5 8 2
sue Advanced 9-10 4 2 4 10 3
Pat Advanced 9-10 5 4 1 10 3
Sam Advanced 9-10 3 5 3 11 5

Please note how ties are ranked.

Is it possible to rank the MPP field since it is a calculated field? In
some of the code I tried I got a 'circular reference' error on the table
name. One alternative I have considered is to change this select query to
an
update query and have a seperate query to update the rank field but would
prefer to get the job done in one pass.

any help is appreciated


.



Relevant Pages

  • Re: ranking calculated fields in a query
    ... I needed to create 3 queries such as you reffered to as qRank. ... Each 'Rank' query uses the ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: ranking calculated fields in a query
    ... I needed to create 3 queries such as you reffered to as qRank. ... Each 'Rank' query uses the associated ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: ranking calculated fields in a query
    ... resolving the ties - I can't help any more with this. ... the rank to appear the way you need it. ... I will look at the other query and reply later. ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: ranking calculated fields in a query
    ... I have just had a quick look at the final query. ... I needed to create 3 queries such as you reffered to as qRank. ... Each 'Rank' query uses the ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: Select Qry: Differing results via Access & ADO (& SQL Server)
    ... So you aren't seeing [Rank] from your query in your ASP pages? ... Inner Join Locations L on P.LocID = L.LocID ...
    (microsoft.public.inetserver.asp.general)