counting within a record

K

Karen

Hi,

Is it possible to count items within a record? For example: I have 12 items
that are classified according to size (i.e. small, medium, large). This
information is entered into 12 fields (i.e. field1, field2, etc.). I would
like to know for each record how many of the 12 items were classified as big.

Any suggestions would be appreciated. Thanks.
 
D

Duane Hookom

I would normalize the table structure. If you can't do that, consider
creating a normalizing union query [quniItemSizes]:
SELECT PkField, Field1 as TheSize, 1 as TheItem
FROM tblNoName
UNION ALL
SELECT PkField, Field2, 2
FROM tblNoName
UNION ALL
SELECT PkField, Field3, 3
FROM tblNoName
UNION ALL
-- etc
SELECT PkField, Field12, 12
FROM tblNoName;

You can then query this
SELECT PkField, Count(*) as NumOf
FROM quniItemSizes
WHERE TheSize = "big"
GROUP BY PkField;
 

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

Top