Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Query in mysql and express does not return what is expected

I have this query using express and mysql, the query in the database works and returns a column with the title "total" and a row with the sum of several expenses. I need to get the number that appears in the row to later show it on the screen with an ajax query, but with the code like this if I enter the link it does not return anything. What can I do? thanks

// GET total spended
router.get('/total', (req, res) => {
  mysqlConnection.query("SELECT (CTE.INCOME - CTE.OUTCOME) AS TOTAL FROM ( SELECT SUM(CASE WHEN operaciones.Tipo= 'Ingreso' THEN COALESCE(operaciones.Monto,0) ELSE 0 END) AS INCOME, SUM(CASE WHEN operaciones.Tipo='gasto' THEN COALESCE(operaciones.Monto,0) ELSE 0 END) AS OUTCOME FROM operaciones ) CTE;", (err, rows, fields) => {
                    
  if (!err) {
    res.json(rows);
  } else {
    console.log(err);
  }
  });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!