I have a table of survey answers, something like:
date | q1 | q2 |
12/12/10 | yes | no |
12/13/10 | no | no |
and I would like to
The first query from spiny norman will give a result like that:
q1 q2 count(*)
no yes 2
yes no 1
yes yes 1
Which only groups couples of distinct results. I assume you want to group the overall number of yes/no by question. In that case, you'd have to do something like that:
SELECT 'q1' as Question, s1.q1 as Answer, count(*) as Count
FROM survey s1
WHERE date>='2010-10-01' AND date<'2010-10-30'
GROUP BY q1
UNION
SELECT 'q2' as Question, q2 as Answer, count(*) as Count
FROM survey
WHERE date>='2010-10-01' AND date<'2010-10-30'
GROUP BY q2
Result:
Question Answer Count
q1 no 2
q1 yes 2
q2 no 1
q2 yes 3