我在 mysql 中有一个视图,运行良好并正确显示结果。
SELECT m.`id_cuota`, m.`clv_cuota`, m.`debe`, m.`haber`,
(select sum(debe) - sum(haber)
from cuotas m2
where m2.id_cuota <= m.id_cuota
) as balance
FROM `cuotas` m
ORDER BY m.`id_cuota` DESC;
id_cuota clv_cuota debe haber balance
22 115 25.00 0.00 125.00
21 115 0.00 150.00 100.00
20 115 50.00 0.00 250.00
19 116 100.00 0.00 200.00
18 115 100.00 0.00 100.00
我想知道如何进行查询,但结果是例如。“clv_cuotas=115”。因此是结果。
id_cuota clv_cuota debe haber balance
22 115 25.00 0.00 25.00
21 115 0.00 150.00 0.00
20 115 50.00 0.00 150.00
18 115 100.00 0.00 100.00