1

Here is my Stored Data. I need the sum of "total". basically I need to fetch overall my sales.

enter image description here

here is my query which returns 0. I have read about how to use sum function but it's not working

USE pharmacy_db;

SELECT SUM(JSON_EXTRACT(Invoice, "$[*].total")) AS sales
FROM sales;

enter image description here

5
  • You use a MySQL JSON function to obtain a JSON array of total values, but there doesn't yet seem to be an array valued function which can take the sum. Commented Nov 27, 2019 at 6:08
  • stackoverflow.com/questions/44997149/… Commented Nov 27, 2019 at 6:12
  • check this post this person also extract sum. but I am unable to fetch total Commented Nov 27, 2019 at 6:13
  • Please share some sample input data, and the expected output from that data in readable form (not as an image) such that others can reproduce your problem Commented Nov 27, 2019 at 7:19
  • Are you using the CONNECT JSON Table Type? Commented Nov 30, 2019 at 11:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.