我有以下数据。我想从总数量(80)中减去第一行,然后从qty1的前一行的数量中减去其余行。
QTY QTY1 DATE TOTAL QTY
2 78 01-JAN-20 80
1 77 15-JAN-20
46 31 22-JAN-20
16 15 27-JAN-20
有办法吗?非常感谢您的帮助。谢谢
4条答案
按热度按时间1bqhqjot1#
示例数据的完整示例:
结果:
oug3syen2#
sql表表示无序集。你的问题似乎取决于行的顺序。假设有一列表示排序。
使用累计和:
这是一把小提琴。
cx6n0qe33#
类似这样的东西(cte只是你的数据):如果你以后再添加任何东西(在“总数量”列中),那么这也会被添加到“总数量”计算中(这对于添加到库存和从库存中减去是典型的)。
7fyelxc54#
你可以做: