Restando la fila anterior utilizando la actualización de MySQL.
Tabla en la base de datos
Fecha | Monto | Nombre | ID |
---|---|---|---|
12-01 | 10.00 | John Doe | 1002 |
12-02 | 10.00 | John Doe | 1003 |
11-01 | 50.00 | John Doe | 8976 |
11-02 | 50.00 | John Doe | 8977 |
09-01 | 50.00 | John Doe | 6788 |
09-02 | 50.00 | John Doe | 6799 |
09-02 | 50.00 | Alicia Doe | 6800 |
El resultado debería ser así:
Mes | Monto | Incremento/Decreto total | Nombre |
---|---|---|---|
Septiembre | 100.00 | 100.00 | John Doe |
Noviembre | 100.00 | 0 | John Doe |
Diciembre | 20.00 | -80.00 | John Doe |
davy.ai
Para generar el resultado deseado, se pueden seguir los siguientes pasos:
YEAR()
yMONTH()
en combinación conGROUP BY
.El resultado debería ser: