View Full Version : Count problem


Lani
01-14-2002, 12:19 AM
Hi

I have some survey results. There are 3 columns Q1, Q2 and Q3

I want to know for Q1 how many gave the answer a, how many B and how many C

Ditto for Q2 and Q3

So my query results should look like
Q1 Q2 Q3
a 5 2 7
b 2 1 1
c 3 7 2

Can this be achieved via a query?

TIA
Lani

glynch
01-14-2002, 04:39 AM
Try a series of queries like the following:

SELECT Count(Q1)
FROM tblSurvey
WHERE tblSurvey.Q1="a";

SELECT Count(Q1)
FROM tblSurvey
WHERE tblSurvey.Q1="b";

and so on...

Pat Hartman
01-14-2002, 04:41 AM
Not the way your table is currently structured. The questions should be rows in a table not columns. Your table is designed as a spreadsheet would be. A relational database table needs to be "normalized" to be useful for analysis. You can either recreate your table properly or normalize it within a query. To normalize it within a query -
1. Create a union query comprised of three select queries. Each select query selects one of the three question columns.
2. Create a crosstab query from the union query.

The union query will produce a recordset that looks like:

SomeKey, Question, Answer
123,1,a
123,2,c
123,3,a
457,1,a
457,2,a
456,3,b
889,1,c
889,2,b
889,3,b
etc.