A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Count



 
 
Thread Tools Display Modes
  #1  
Old November 21st, 2006, 09:23 PM posted to microsoft.public.access.queries
Dan @BCBS
external usenet poster
 
Posts: 195
Default Count

I need to find the top 20 most used answers. In this case the answers are
procedure codes.

Is there a way to do a frequency for each code, then report out the top 20??
Or some other way??

This code just gives me a total count of all codes: I need a count of each
distinct code, but I cannot use distinct because it only gives me 1 for each.

SELECT Count(tblTrackingData.TR_CPTCode) AS CountOfTR_CPTCode
FROM tblTrackingData;


  #2  
Old November 21st, 2006, 09:54 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Count

Try this ---

SELECT TOP 20 tblTrackingData.TR_CPTCode, Count(tblTrackingData.TR_CPTCode)
AS CountOfCode
FROM [tblTrackingData]
GROUP BY tblTrackingData.TR_CPTCode
ORDER BY Count(tblTrackingData.TR_CPTCode) DESC;

If number twenty is tied with twenty-one then you will get 21 in the results.

"Dan @BCBS" wrote:

I need to find the top 20 most used answers. In this case the answers are
procedure codes.

Is there a way to do a frequency for each code, then report out the top 20??
Or some other way??

This code just gives me a total count of all codes: I need a count of each
distinct code, but I cannot use distinct because it only gives me 1 for each.

SELECT Count(tblTrackingData.TR_CPTCode) AS CountOfTR_CPTCode
FROM tblTrackingData;


  #3  
Old November 22nd, 2006, 01:10 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Count

If you don't want to show ties for the last position (I would show ties),
then you can add the TR_CPTCode to the sort.

SELECT TOP 20 tblTrackingData.TR_CPTCode
, Count(tblTrackingData.TR_CPTCode) AS CountOfCode
FROM [tblTrackingData]
GROUP BY tblTrackingData.TR_CPTCode
ORDER BY Count(tblTrackingData.TR_CPTCode) DESC
, tblTrackingData.TR_CPTCode

"KARL DEWEY" wrote in message
...
Try this ---

SELECT TOP 20 tblTrackingData.TR_CPTCode,
Count(tblTrackingData.TR_CPTCode)
AS CountOfCode
FROM [tblTrackingData]
GROUP BY tblTrackingData.TR_CPTCode
ORDER BY Count(tblTrackingData.TR_CPTCode) DESC;

If number twenty is tied with twenty-one then you will get 21 in the
results.

"Dan @BCBS" wrote:

I need to find the top 20 most used answers. In this case the answers
are
procedure codes.

Is there a way to do a frequency for each code, then report out the top
20??
Or some other way??

This code just gives me a total count of all codes: I need a count of
each
distinct code, but I cannot use distinct because it only gives me 1 for
each.

SELECT Count(tblTrackingData.TR_CPTCode) AS CountOfTR_CPTCode
FROM tblTrackingData;




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.