I have a table that contains a JSON column in it, say for example
CREATE TABLE test(jsonValue JSON)
And I have multiple values int it:
INSERT INTO test('{"a": 1}');
INSERT INTO test('{"a": 3}');
INSERT INTO test('{"b": 4}');
INSERT INTO test('{"b": 10}');
I would like to return a result where I merge all JSONs to a single one with the sum of the values in each JSON. So Result should be
{
"a": 4,
"b": 14
}
OR, an easier solution (using JSON_MERGE_PRESERVE)
{
"a": [1, 3],
"b": [4, 10]
}
How can I do this? I have little SQL knowledge and I can't seem to figure our how to write this query. Any help will be very appreciated, thanks!