I'm looking so long, and cannot find anything right concerning – ho to sum the values from JSON column.
My values in the column looks like this:
[{"file":"FILE.doc",
"POSITION":"3245",
"NUMBER":"2345",
"PRICE":"123",
"PRICE2":"3456",
"NUMBER":"2019-01-25",
"date":"2019\/01\/15",
"added_by":"admin"
},{
"file":"FILE.doc",
"POSITION":"345",
"numer_faktury":"456",
"PRICE":"125",
"PRICE2":"567",
"DATE":"2019-01-11",
"DATE":"2019\/01\/15",
"added_by":"admin"
}]
Table = table
column = prices
My select to extract the values looks as follow:
SELECT JSON_EXTRACT(prices,
'$[*].PRICE') as quality FROM table
WHERE employee_id = 10060
And I've got this:
| QUALITY |
["123", "125"]
Is there any possible to sum the values and get:
| QUALITY |
| ["248"] |
Best Answer
Another way to solve this would be by using Recursive Common Table Expressions which is available since MariaDB 10.2.2. This solution does not need a
numbers
table but recursively iterates the result until the computation of the SUM is complete.I made a small example which is similar to your data:
Now the actual query to retrieve the result: