Giving the following json field in a table column:
[
{
"payment_date":"2016-04-26",
"amount":590,
"payment_method":"2"
},
{
"payment_date":"2017-05-01",
"amount":208,
"payment_method":"4"
}
]
How could I sum all the amounts?
The farthest I could get is
SELECT JSON_EXTRACT(`payment_lines`, '$[*].amount') FROM tbl
which returns:
[590, 208]
What I would need to get is this sum of 590 and 208. So to say that in this case there are two rows but there might be many more.
SELECT VERSION();
10.2.6-MariaDB-10.2.6+maria~jessie-log