I have survey_results
table which has following columns:
id - integer
score_labels - jsonb
score_labels
column data format looks like this:
{"total": "High", "risk": "High"}
Now I want to have sql query that will group and count my survey results by this score_labels
column. This is what the final result should look like:
total risk
------- ------
{high: 2, medium: 1, low: 0} {high: 1, medium: 2, low: 1}
I want to count survey results by its score labels. Is there way to do it in PostgreSQL?
Here is simple sqlfiddle with the following schema:
A somewhat complicated kind of aggregation: