Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/01/2016, 15:34
Avatar de gnzsoloyo
gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Sumar ResultadoConsulta con Otro Dato. (Mysql+JavaNetbeans+JasperReports)

Todo depende del ingenio...

Dos soluciones posibles:
Código MySQL:
Ver original
  1.     SUM(total) NetoMes
  2.     (SELECT
  3.         SUM(ingresoxDia) total
  4.     FROM
  5.         caja
  6.     WHERE
  7.         YEAR(fechaAbrir) = 2015
  8.             AND MONTH(fechaAbrir) = 12
  9.         SUM(cantidad) * - 1 total
  10.     FROM
  11.         gastos
  12.     WHERE
  13.         YEAR(fechaEgreso) = 2015
  14.             AND MONTH(fechaEgreso) = 12
  15.             AND categoria <> 'RETIRO DE EFECTIVO'
  16.             AND categoria <> 'SERVICIOS'
  17.     SELECT
  18.         IFNULL(SUM(cantidad), 0) * - 1 total
  19.     FROM
  20.         pagoservicios
  21.     WHERE
  22.         YEAR(fecha) = 2015 AND MONTH(fecha) = 12) saldos;

Código MySQL:
Ver original
  1.     IngresoMes,
  2.     GastosMes,
  3.     PagosMes,
  4.     (IngresoMes - GastosMes - PagosMes) SaldoMes
  5.     (SELECT
  6.         SUM(ingresoxDia) IngresoMes
  7.     FROM
  8.         caja
  9.     WHERE
  10.         YEAR(fechaAbrir) = 2015
  11.             AND MONTH(fechaAbrir) = 12) Ingreso
  12.         JOIN
  13.     (SELECT
  14.         SUM(cantidad) GastosMes
  15.     FROM
  16.         gastos
  17.     WHERE
  18.         YEAR(fechaEgreso) = 2015
  19.             AND MONTH(fechaEgreso) = 12
  20.             AND categoria <> 'RETIRO DE EFECTIVO'
  21.             AND categoria <> 'SERVICIOS') Gastos
  22.         JOIN
  23.     (SELECT
  24.         IFNULL(SUM(cantidad), 0) PagosMes
  25.     FROM
  26.         pagoservicios
  27.     WHERE
  28.         YEAR(fecha) = 2015 AND MONTH(fecha) = 12) Pagos
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)