【发布时间】:2014-08-04 05:16:12
【问题描述】:
根据我之前回答的问题,我想知道如何使用 postgres 触发器进行类似的余额计算。
how to calculate balances in an accounting software using postgres window function
ID Date In Out Balance
1 1/1 100.00 0.00 100.00
2 2/1 10.00 0.00 110.00
3 3/1 0.00 70.00 40.00
4 5/1 5.00 0.00 45.00
5 6/1 0.00 60.00 -15.00
现在我需要一个“触发器”,它会给我以下结果:
ID Date In Out Balance
1 1/1 100.00 0.00 100.00
2 2/1 10.00 0.00 110.00
3 3/1 0.00 70.00 40.00
6 4/1 20.00 0.00 60.00 <--- inserted new row
4 5/1 5.00 0.00 65.00
5 6/1 0.00 60.00 5.00
如何在 postgres 中创建触发器来更新“连续”行的余额(不更新旧行)?
【问题讨论】:
标签: sql postgresql database-design triggers