我正在尝试计算运行总计。但是,当累积总和大于另一个列的值时,应该重置 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 …