Is it possible to calculate sum of json values grouped by json keys?
Mysql version is 5.7.17 on Google cloud sql.
Example_1: A short example of my point:
col1 | col2
-----|-----------------------
aaa | {"key1": 1, "key2": 3}
-----|-----------------------
bbb | {"key1": 0, "key2": 2}
-----|-----------------------
aaa | {"key1": 50, "key2": 0}
SQL query should produce:
col1 | col2
-----|-----------------------
aaa | {"key1": 51, "key2": 3}
-----|-----------------------
bbb | {"key1": 0, "key2": 2}
OR
will it be possible with any of the below schema?
Example_2:
col1 | col2
-----|-----------------------
aaa | {{"key_name" : "key1", "key_value" : 1}, {"key_name" : "key2", "key_value" : 3}}
-----|-----------------------
bbb | {{"key_name" : "key1", "key_value" : 0}, {"key_name" : "key2", "key_value" : 2}}
-----|-----------------------
aaa | {{"key_name" : "key1", "key_value" : 50}, {"key_name" : "key2", "key_value" : 0}}
Example_3:
col1 | col2
-----|-----------------------
aaa | [{"key_name" : "key1", "key_value" : 1}, {"key_name" : "key2", "key_value" : 3}]
-----|-----------------------
bbb | [{"key_name" : "key1", "key_value" : 0}, {"key_name" : "key2", "key_value" : 2}]
-----|-----------------------
aaa | [{"key_name" : "key1", "key_value" : 50}, {"key_name" : "key2", "key_value" : 0}]
Example_4:
col1 | col2
-----|-----------------------
aaa | {"key1": {"key_name" : "key1", "key_value" : 1}, "key2": {"key_name" : "key2", "key_value" : 3}}
-----|-----------------------
bbb | {"key1": {"key_name" : "key1", "key_value" : 0}, "key2": {"key_name" : "key2", "key_value" : 2}}
-----|-----------------------
aaa | {"key1": {"key_name" : "key1", "key_value" : 50}, "key2": {"key_name" : "key2", "key_value" : 0}}