A
Alan
I know this topic has been visited before. I followed the suggestions (and
my own variants) I found in the search results, but I can't quite get tha
ranking to work. I guess it's been too long since I dealt with sub-queries.
This is for a scoring database. Here's my setup. I have one table that
lists dog names and their owners with a key field called ID that is
auto-number. I have another table that lists different events, the event
location, and the number of dogs in each class (section) in that event. This
table also has a key field called EventID that is auto-number. There is a
3rd table that simply lists weight classes. The weight field is auto-number
from 1-160 (but it doesn't have to be auto-number), and the Class field is A,
B, C, D, or Open (D is 59 and down, C is 60-80, B is 81-100, A is 101-120,
Open is 121 and up). Finally, I have a fourth table that is a compilation of
all the results for the various events. This table has eventID, dogID (both
linked to their respective tables), Dog Weight (link to class table), times,
distances, other generic fields, and finish place. This table also has a key
field that is auto-number.
I have a query that searches the Results table for all of it's fields, dog
name and owner from the dog table, and add 3 calculated fields. The first is
if any bonus points are earned for that event, and the second is total points
earned for that event, and last is weight percentage. This query works fine.
It's long but here it is.
SELECT tblResults.Event_ID, tblEvents.Event_Name, tblClass.Class,
tblDogs.[Dog Name], tblDogs.ID, tblDogs.Owner, tblDogs.Sex,
tblResults.Dog_Wt, tblResults.Cert, tblResults.Ex, tblResults.Cplt_Wt,
tblResults.Time, tblResults.Final_Wt, tblResults.Dist, tblResults.Place,
IIf(tblResults!Cplt_Wt<400,0,5) AS Bonus,
IIf([Bonus]=0,0,IIf(tblClass!Class="D",(tblEvents!D_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="C",(tblEvents!C_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="B",(tblEvents!B_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="A",(tblEvents!A_Count-(tblResults!Place-1)+[Bonus]),(tblEvents!O_Count-(tblResults!Place-1)+[Bonus]))))))
AS Points, Round(tblResults!Cplt_Wt/tblResults!Dog_Wt,2) AS xbdywt
FROM tblClass INNER JOIN (tblEvents INNER JOIN (tblDogs INNER JOIN
tblResults ON tblDogs.ID = tblResults.Dog_ID) ON tblEvents.Event_ID =
tblResults.Event_ID) ON tblClass.Weight = tblResults.Dog_Wt;
I have a second query searching the results of the first query. This one
groups by class, then adds the points for each dog, and displays in
descending order.
SELECT DISTINCTROW qryAll_Results.Class, qryAll_Results.[Dog Name],
qryAll_Results.Owner, Sum(qryAll_Results.Points) AS Points
FROM qryAll_Results
GROUP BY qryAll_Results.Class, qryAll_Results.[Dog Name],
qryAll_Results.Owner, qryAll_Results.ID;
This query also does exactly what I want it to.
I want to rank these in order by points, most points wins, keeping them
grouped by class. I've gotten them all to be in last place, or all to be in
first place.
Is this better done using VBA?
my own variants) I found in the search results, but I can't quite get tha
ranking to work. I guess it's been too long since I dealt with sub-queries.
This is for a scoring database. Here's my setup. I have one table that
lists dog names and their owners with a key field called ID that is
auto-number. I have another table that lists different events, the event
location, and the number of dogs in each class (section) in that event. This
table also has a key field called EventID that is auto-number. There is a
3rd table that simply lists weight classes. The weight field is auto-number
from 1-160 (but it doesn't have to be auto-number), and the Class field is A,
B, C, D, or Open (D is 59 and down, C is 60-80, B is 81-100, A is 101-120,
Open is 121 and up). Finally, I have a fourth table that is a compilation of
all the results for the various events. This table has eventID, dogID (both
linked to their respective tables), Dog Weight (link to class table), times,
distances, other generic fields, and finish place. This table also has a key
field that is auto-number.
I have a query that searches the Results table for all of it's fields, dog
name and owner from the dog table, and add 3 calculated fields. The first is
if any bonus points are earned for that event, and the second is total points
earned for that event, and last is weight percentage. This query works fine.
It's long but here it is.
SELECT tblResults.Event_ID, tblEvents.Event_Name, tblClass.Class,
tblDogs.[Dog Name], tblDogs.ID, tblDogs.Owner, tblDogs.Sex,
tblResults.Dog_Wt, tblResults.Cert, tblResults.Ex, tblResults.Cplt_Wt,
tblResults.Time, tblResults.Final_Wt, tblResults.Dist, tblResults.Place,
IIf(tblResults!Cplt_Wt<400,0,5) AS Bonus,
IIf([Bonus]=0,0,IIf(tblClass!Class="D",(tblEvents!D_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="C",(tblEvents!C_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="B",(tblEvents!B_Count-(tblResults!Place-1)+[Bonus]),IIf(tblClass!Class="A",(tblEvents!A_Count-(tblResults!Place-1)+[Bonus]),(tblEvents!O_Count-(tblResults!Place-1)+[Bonus]))))))
AS Points, Round(tblResults!Cplt_Wt/tblResults!Dog_Wt,2) AS xbdywt
FROM tblClass INNER JOIN (tblEvents INNER JOIN (tblDogs INNER JOIN
tblResults ON tblDogs.ID = tblResults.Dog_ID) ON tblEvents.Event_ID =
tblResults.Event_ID) ON tblClass.Weight = tblResults.Dog_Wt;
I have a second query searching the results of the first query. This one
groups by class, then adds the points for each dog, and displays in
descending order.
SELECT DISTINCTROW qryAll_Results.Class, qryAll_Results.[Dog Name],
qryAll_Results.Owner, Sum(qryAll_Results.Points) AS Points
FROM qryAll_Results
GROUP BY qryAll_Results.Class, qryAll_Results.[Dog Name],
qryAll_Results.Owner, qryAll_Results.ID;
This query also does exactly what I want it to.
I want to rank these in order by points, most points wins, keeping them
grouped by class. I've gotten them all to be in last place, or all to be in
first place.
Is this better done using VBA?