Given N records that contain a json column
|ID |Name |JSON
|01 |TEST1 |{"key1" : "value1", "key2": "value2", "key4": "value4"}
|02 |TEST1 |{"key1" : "value1"}
|03 |TEST2 |{"key1" : "value1", "key2": "value2", "key3":"value3"}
...
What would be the best strategy to count the occurrences of each json value for a set of keys, such that for the example above I would restrict to key1, key2, key3 and get:-
|value1|value2|value3|
|3 |2 |1 |
The values will change so I don't really want to look for them explicitly.