Jorch Cab Asked: 2020-09-26 22:04:36 +0800 CST 2020-09-26 22:04:36 +0800 CST 2020-09-26 22:04:36 +0800 CST How can I calculate the balance column of a mysql table?, as if it were a bank statement 772 The SQL statement that I have does not do the correct calculation, what I expect is: saldo 100 50 40 340 370 php 1 Answers Voted Best Answer Marcos 2020-09-27T02:30:42+08:002020-09-27T02:30:42+08:00 You could solve it using a variable . Example: SET @acumulador=0; SELECT concepto, cargo, abono, @acumulador:=(cargo - abono + @acumulador) AS saldo FROM poliza_detalles; Demo
You could solve it using a variable .
Example:
Demo