I have a table that has data like:
id, array_json
123, [{"Name": "John", "Age": "12"}, {"Name": "Jane", "Age": "18"}, {"Name": "Jake", "Age": "34"}]
124, [{"Name": "Dolly", "Age": "12"}, {"Name": "Molly", "Age": "18"}, {"Name": "Rosa", "Age": "34"}]
123, []
125, [{"Name": "Dolly", "Age": "12"}, {"Name": "Dolly", "Age": "18"}, {"Name": "Holt", "Age": "34"}]
Its basically an id mapped to an array of jsons, which is a jsonb. I want the output to be all the unique names (Key is "Name") & their count as follows:
id, Unique_Names, Count
123, ["John", "Jane", "Jake"], 3
124, ["Dolly", "Molly", "Rosa"], 3
125, [], 0
126, ["Dolly", "Holt"], 2
How do I do this in postgres?