Ver Mensaje Individual
  #11 (permalink)  
Antiguo 24/06/2009, 13:07
Avatar de huesos52
huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: sumar 2 valores

De todos, creo que jurena fue quien mejor entendió el problema.

prueba esto:
Código sql:
Ver original
  1. SELECT date_format(f2.fecha,'%Y-%m')fecha1, date_format(f1.fecha,'%Y-%m') fecha2, (f2.lec2-f1.lec1)gasto
  2. FROM (SELECT fecha,SUM(lectura)lec1 FROM locales GROUP BY date_format(fecha,'%Y-%m'))f1 INNER JOIN
  3. (SELECT fecha,SUM(lectura)lec2 FROM locales GROUP BY date_format(fecha,'%Y-%m')) f2
  4. ON (DATE_FORMAT(f1.fecha,'%Y-%m') = DATE_FORMAT(DATE_sub(f2.fecha, INTERVAL 1 MONTH),'%Y-%m'))
  5. ORDER BY fecha1;

Nos cuentas como te va.
__________________
Without data, You are another person with an opinion.
W. Edwads Deming