Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda