Genial.
Ahora veamos si se entiende la lógica que te propongo, y también si se entiende.
Tablas:
Código MySQL:
Ver originalQuery OK, 0 rows affected (0.07 sec)
Query OK, 0 rows affected (0.03 sec)
Query OK, 0 rows affected (0.07 sec)
mysql>
Query OK, 0 rows affected (0.06 sec)
Datos imaginarios:
Código MySQL:
Ver original -> VALUES (800, '2016-01-10'), (660, '2016-01-15'), (365, '2016-02-18'), (524, '2016-02-21'), -> (330, '2016-03-10'), (123, '2016-03-15'), (450, '2016-04-18'), (500, '2016-04-21');
Query OK, 8 rows affected (0.03 sec)
mysql>
-> VALUES (250, '2016-01-10'), (300, '2016-01-15'), (121, '2016-02-18'), (320, '2016-02-21'), -> (320, '2016-03-10'), (200, '2016-03-15'), (150, '2016-04-18'), (190, '2016-04-21');
Query OK, 8 rows affected (0.02 sec)
Consulta:
Código MySQL:
Ver original -> ing.Mes, ing.Anio, Ingresos, Gastos, (ingresos - gastos) saldo
-> cajamonto
-> cajachica
-> AND ing.anio
= gts.anio
+------+------+----------+--------+--------+
| Mes | Anio | Ingresos | Gastos | saldo |
+------+------+----------+--------+--------+
| 1 | 2016 | 1460.00 | 550.00 | 910.00 |
| 2 | 2016 | 889.00 | 441.00 | 448.00 |
| 3 | 2016 | 453.00 | 520.00 | -67.00 |
| 4 | 2016 | 950.00 | 340.00 | 610.00 |
+------+------+----------+--------+--------+
¿Estamos más cerca?