Display highest rate of record

  • Thread starter ghostman via AccessMonster.com
  • Start date
G

ghostman via AccessMonster.com

on my query based on two tables [Trainees] & [Training Records], how can i
display the Contractor (or Company) with the highest number of NoShows?

ContractorName = Text Field
NoShow = Yes/No Field

So far i got 2 Contractors in my record.

CONTRACTORNAME TOTAL NOSHOW
Contractor 1 2
Contractor 2 5

query should display:

CONTRACTORNAME TOTAL NOSHOW
Contractor 2 5

i have this SQL:

SELECT Trainees.ContractorName, Count([Training Records].NoShow) AS
CountOfNoShow
FROM Trainees INNER JOIN [Training Records] ON Trainees.TraineeID = [Training
Records].TraineeID
GROUP BY Trainees.ContractorName;

Thanks again!
 
J

Jeanette Cunningham

Hi ghostman,
make it a Top 1 query.
In the property sheet for the query, find the property for Top Values and
put 1 for the top value.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
G

ghostman via AccessMonster.com

thanks for the response :)

i tried what you have said but it shows the other one:

CONTRACTORNAME TOTAL NOSHOW
Contractor 1 2


SELECT TOP 1 Trainees.ContractorName, Count([Training Records].NoShow) AS
CountOfNoShow
FROM Trainees INNER JOIN [Training Records] ON Trainees.TraineeID = [Training
Records].TraineeID
GROUP BY Trainees.ContractorName;


Jeanette said:
Hi ghostman,
make it a Top 1 query.
In the property sheet for the query, find the property for Top Values and
put 1 for the top value.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
on my query based on two tables [Trainees] & [Training Records], how can i
display the Contractor (or Company) with the highest number of NoShows?
[quoted text clipped - 23 lines]
Thanks again!
 
J

John Spencer

In a top query you must sort by the value that determines the top.

SELECT TOP 1 Trainees.ContractorName
, Count([Training Records].NoShow) AS CountOfNoShow
FROM Trainees INNER JOIN [Training Records]
ON Trainees.TraineeID = [Training Records].TraineeID
GROUP BY Trainees.ContractorName
ORDER BY Count([Training Records].NoShow) DESC

The problem here is that counting a boolean field (no show) would be the same
as counting the number of records. Count counts the presence of a value and
the field NoShow will always have a value (either True or False).

You can fix that in a variety of ways. The simplest way to fix it with this
query is to add a where clause.

SELECT TOP 1 Trainees.ContractorName
, Count([Training Records].NoShow) AS CountOfNoShow
FROM Trainees INNER JOIN [Training Records]
ON Trainees.TraineeID = [Training Records].TraineeID
WHERE NoShow = True
GROUP BY Trainees.ContractorName
ORDER BY Count([Training Records].NoShow) DESC

If you have more than one contractor with the highest number of NoShows then
you will get multiple records returned.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
thanks for the response :)

i tried what you have said but it shows the other one:

CONTRACTORNAME TOTAL NOSHOW
Contractor 1 2


SELECT TOP 1 Trainees.ContractorName, Count([Training Records].NoShow) AS
CountOfNoShow
FROM Trainees INNER JOIN [Training Records] ON Trainees.TraineeID = [Training
Records].TraineeID
GROUP BY Trainees.ContractorName;


Jeanette said:
Hi ghostman,
make it a Top 1 query.
In the property sheet for the query, find the property for Top Values and
put 1 for the top value.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
on my query based on two tables [Trainees] & [Training Records], how can i
display the Contractor (or Company) with the highest number of NoShows?
[quoted text clipped - 23 lines]
Thanks again!
 
G

ghostman via AccessMonster.com

Thanks John!

John said:
In a top query you must sort by the value that determines the top.

SELECT TOP 1 Trainees.ContractorName
, Count([Training Records].NoShow) AS CountOfNoShow
FROM Trainees INNER JOIN [Training Records]
ON Trainees.TraineeID = [Training Records].TraineeID
GROUP BY Trainees.ContractorName
ORDER BY Count([Training Records].NoShow) DESC

The problem here is that counting a boolean field (no show) would be the same
as counting the number of records. Count counts the presence of a value and
the field NoShow will always have a value (either True or False).

You can fix that in a variety of ways. The simplest way to fix it with this
query is to add a where clause.

SELECT TOP 1 Trainees.ContractorName
, Count([Training Records].NoShow) AS CountOfNoShow
FROM Trainees INNER JOIN [Training Records]
ON Trainees.TraineeID = [Training Records].TraineeID
WHERE NoShow = True
GROUP BY Trainees.ContractorName
ORDER BY Count([Training Records].NoShow) DESC

If you have more than one contractor with the highest number of NoShows then
you will get multiple records returned.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
thanks for the response :)
[quoted text clipped - 20 lines]
[quoted text clipped - 23 lines]
Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Yes/No 7
Count YES/NO Field 2
Report 3
Join on a calculated field 5
count record 6
Active/Inactive - REPORTING 1
relationship - query 2
query / combo box 14

Top