Questions tagged «running-totals»


2
根据更改日志计算库存数量
假设您具有以下表结构: LogId | ProductId | FromPositionId | ToPositionId | Date | Quantity ----------------------------------------------------------------------------------- 1 | 123 | 0 | 10002 | 2018-01-01 08:10:22 | 5 2 | 123 | 0 | 10003 | 2018-01-03 15:15:10 | 9 3 | 123 | 10002 | 10004 | 2018-01-07 21:08:56 | 3 4 …

4
根据另一列重置运行总计
我正在尝试计算运行总计。但是,当累积总和大于另一个列的值时,应该重置 create table #reset_runn_total ( id int identity(1,1), val int, reset_val int, grp int ) insert into #reset_runn_total values (1,10,1), (8,12,1),(6,14,1),(5,10,1),(6,13,1),(3,11,1),(9,8,1),(10,12,1) SELECT Row_number()OVER(partition BY grp ORDER BY id)AS rn,* INTO #test FROM #reset_runn_total 索引详细信息: CREATE UNIQUE CLUSTERED INDEX ix_load_reset_runn_total ON #test(rn, grp) 样本数据 +----+-----+-----------+-----+ | id | val | reset_val …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.