To count records in a query (1 Viewer)

JRPMD

Registered User.
Local time
Today, 09:27
Joined
Nov 24, 2012
Messages
52
Hello, I have a field in a table with a restricted number of values from 1 to 10.
I consider each number a category and I want to count how many records there are in each one.
I can group and count the records in a query but there are only nine criteria to fill in , so the last number cannot be counted.
Is there another or a better way to do this?
For example , a visual basic code?
Thank you very much!
 

Ranman256

Well-known member
Local time
Today, 12:27
Joined
Apr 9, 2015
Messages
4,337
Can you not use a count query?
Or
Use DCOUNT()
 

plog

Banishment Pending
Local time
Today, 11:27
Joined
May 11, 2011
Messages
11,646
I consider each number a category and I want to count how many records there are in each one.

That can be accomplished with a simple aggregate query:

Code:
SELECT CategoryNumber, COUNT(CategoryNumber) AS TotalRecords
FROM YourTableNameHere
GROUP BY CategoryNumber;

But this part doesn't make sense:

I can group and count the records in a query but there are only nine criteria to fill in , so the last number cannot be counted.

You lost me there. What does criteria have to do with this? Please demonstrate your issue with data please.
 

JRPMD

Registered User.
Local time
Today, 09:27
Joined
Nov 24, 2012
Messages
52
Thank you very much for your useful answers.
Sorry if a I lost you with the criteria I´m trying to use ; I don't know the exact translation of "criterios" from my spanish version of MS Access.
Finally I grouped a field in a query in this way : "1" or "2" or "3" or "4" , etc .
Thanks again!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:27
Joined
Feb 28, 2001
Messages
27,182
OK, if you wanted something shorter AND (for example) 1 to 9 would work, you could use the BETWEEN ... AND relational operator:

Code:
A BETWEEN 1 AND 9

Easier than a chain of OR segments.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:27
Joined
Feb 19, 2002
Messages
43,270
Use the crosstab query wizard to build this query if you want the columns displayed in a single row. The crosstab will support a maximum of 254 values and so if you add an 11th value, you won't have to change anything.

To display the counts in a list, use the following.

Select Category, Count(*) As CatCount From YourTable
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:27
Joined
Feb 28, 2001
Messages
27,182
For future reference: If you are doing from 1 to 9, then A BETWEEN 1 AND 9 works great. But suppose you wanted to do 1, 3, 5, 7, 9? Try A IN (1,3,5,7,9) which works ok for short lists. If the list is a lot longer, you can also use a reference table that contains your list in, say, field B. Then use A IN ( SELECT B FROM ReferenceTable ) as a way to select when you have a lot of non-contiguous options.
 

Users who are viewing this thread

Top Bottom