I have a table in which I have form id and the form fields column
=======================
form_id | form_fields
=======================
1 | [abc,def]
Now there is one other table that contains the submitted form's response data like this
================================
device_id | form_id | response
================================
101 | 1 | {abc:true}
================================
102 | 1 | {def:true}
================================
103 | 1 | {def:true}
================================
101 | 2 | {xyz :true}
I want to get all the count of array values of form_fields of form_id 1 in the first table from the second table. I mean result be like
{abc:1,def:2}
One way is to make a simple json of all the responses then iterate one by one object of json and check the values. Is there any other efficient and better way to solve this? I am new to postgres so please ignore if this is too basic to ask.
Thanks!