【发布时间】:2020-06-17 06:59:17
【问题描述】:
我有上个月的期末余额,我想根据上个月的期末余额计算每天的流动余额。我尝试的如下
DECLARE @TestTable TABLE
(
id int,
somedate date,
Credit INT,
Debit INT
)
DECLARE @LastMothClosing INT=2000
insert into @TestTable values
(1, '01/Jan/20', 1000,100),
(2, '02/Jan/20', 0,0),
(3, '03/Jan/20', 500,500),
(4, '04/Jan/20', 1000,200),
(5, '05/Jan/20', 100,50)
select id,
somedate,
Credit,
Debit,
(Credit-Debit)+ (SUM(@LastMothClosing) over(order by somedate rows unbounded preceding)) as runningtotal
from @TestTable
我想将前一天的期末余额添加到第二天的贷方金额中,然后它应该从借方金额中减去以获得余额等等。
【问题讨论】:
标签: sql-server sql-server-2012