Chart JS的SQL查询

I have the a table like this.

| id  | question_id | option_id |
---------------------------------
| 1   |         1   |         1 |
| 1   |         1   |         2 |
| 1   |         1   |         3 |
| 1   |         1   |         2 |
| 1   |         1   |         2 |
| 1   |         1   |         6 |

How would I query for the result as follows?

[
  {'1' => 1},
  {'2' => 3},
  {'3' => 1},
  {'4' => 0},
  {'5' => 0},
  {'6' => 1},
]

Currently what I have is by looping the query from 1 to 6. Is there a way for me to query the counts for all possible value of option_id without knowing about the possible values (1 to 6)?

Select sum(case when option_id = 1 then 1 else 0 end) as "1" FROM fcs_answer WHERE question_id = 4;

A valid query could be:

SELECT option_id, COUNT(*) FROM my_table GROUP BY option_id;

Everything else can be handled in application code

Try this query. i think so it is useful

SELECT `option_id `,SUM(1) FROM table_name
GROUP BY `option_id `