Solution 1: Two queries
You should use a table that contains your desired (correct) answer types:
| id | answer |
---------------
| 1 | a1 |
| 2 | a2 |
etc.
Then you can count the results that actually exist in your table:
SELECT atype, COUNT( * ) cnt FROM answers JOIN mytable
ON mytable.atype=answers.answer GROUP BY answers.answer;
(Replace mytable with the appropriate table name).
Of course, this will only return existing results. To count the zero rows, you can look for answers that do not appear in your table:
SELECT answer, '0' AS cnt FROM answers WHERE answer NOT IN(
SELECT DISTINCT answer FROM answers JOIN mytable WHERE answer=mytable.atype );
Here is an example.
Solution 2: A counter table
Another way would be to use a counter table:
| id | answer | cnt |
---------------------
| 1 | a1 | 0 |
| 2 | a2 | 0 |
etc.
Then every time you want to count the results, do:
UPDATE answers SET cnt=0;
UPDATE answers SET cnt=
(SELECT cnt FROM
((SELECT answers.answer, COUNT(*) AS cnt
FROM answers JOIN mytable ON answers.answer=myTable.aType
GROUP BY answers.answer) AS tbl)
WHERE answers.answer=tbl.answer)
WHERE EXISTS
(SELECT cnt FROM
((SELECT answers.answer, COUNT(*) AS cnt
FROM answers JOIN mytable ON answers.answer=mytable.atype
GROUP BY answers.answer) AS tbl)
WHERE answers.answer=tbl.answer);
This will update the counter values in your answers table, and you can just SELECT * FROM answers ORDER BY answer to get your result.
Be warned, though: I believe the second version, while convenient, will take a lot more computing power than the first one, due to all the subqueries needed.
Here is this example (UPDATE statements are on the left side!)
Solution 3: Update upon write
The best and least performance hungry solution for use cases like yours, in my opinion, is to create a counter table like the one I described in #2, but update the counter values at the time users are answering the questions, instead of re-calculating all the entries everytime you want to know the count.
This can easily be done. Everytime a question is answered correctly, increase the counter in the answers table:
UPDATE answers SET cnt=cnt+1 WHERE answers.answer='a1';
And again, your query will be
SELECT * FROM answers ORDER BY answer;