-1

I Have one table i.e discount_details. I have 2 columns are the ID , DiscountTotal. I want to sum the each record line total json object with in the D array (64,10,10 are the 1st record values) . Like here 64,10,10 are the values,need to sum total value as 84 in the select query of MYSQL. I tried below examples but not working. Can please help on this issue.

SELECT  JSON_EXTRACT(`DiscountTotal`, '$.D') AS total FROM tablename 

enter image description here

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828

1 Answers1

0

Here is the query:

SELECT s.SNO, sum(t.Value)
FROM tablename s, 
     JSON_TABLE(
         JSON_EXTRACT(`DiscountTotal`,'$[0].D'),
         "$[*]" COLUMNS(
           Value INT PATH "$"
         )
       ) t group by s.SNO
Aymendps
  • 1,346
  • 4
  • 20