1

I'm getting an effective return calculation of all values column my MYSQL table but when i went to check my api result; the column value sum command is appearing in the result of the JSON.

   [
      {
        "SUM(producFinalPrice)": 6000
      }
    ]

This my router get data from my data base.

router.get('/sell/home-card-last-sell-compared-to-the-previous-day', function (req, res) {
  connection.query('SELECT SUM(producFinalPrice) FROM new_sell',
    function (err, lastSellComparedToThePreviousDayCardHome, fields) {
      if (err) {
        throw err;
      }
      res.send(lastSellComparedToThePreviousDayCardHome);
    }
  );
});

`

Making my mistake clearer, i'm making the final request from the previous query in AJAX; Through this way.

$(function () {
  $.ajax({
    type: "GET",
    url: "/sell/home-card-last-sell-compared-to-the-previous-day",
    success: function (lastSellComparedToThePreviousDayCardHome) {
      var $lastSellComparedPreviousDay = $('#last-sell-compared-to-the-previous-day');
      $.each(lastSellComparedToThePreviousDayCardHome, function (i, SellPreviousDay) {
        $lastSellComparedPreviousDay.append('<li>R$ ' + SellPreviousDay.producFinalPrice + '.</li>');
      });
      console.log('Sucess return to Last Sell Previous Day!', lastSellComparedToThePreviousDayCardHome);
    }
  });
});

Basically that's it I could not find anything that would help me.. Thanks for helping me out ;]

1 Answer 1

1

Use an alias:

connection.query('SELECT SUM(producFinalPrice) AS productFinalSum FROM new_sell', ...
                                               ^^^^^^^^

Then when you parse your JSON in Node check for the productFinalSum key. Actually, I think you could even use SUM(productFinalSum) to access your JSON, but it looks awkward.

Sign up to request clarification or add additional context in comments.

1 Comment

NICE worked perfectly. Thanks tim b. i marked as answered in 8 minutes xD

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.