Questions tagged [running-totals]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
4 answers

Set non-negative floor for rolling sum, in PostgreSQL

This is a really fun question (asked for SQL Server) and I wanted to try it out to see how it was done in PostgreSQL. Let's see if anyone else can do it better. Taking this data, CREATE TABLE foo AS ...
Evan Carroll's user avatar
  • 63.1k
11 votes
4 answers

Reset Running Total based on another column

Am trying to calculate running total. But it should reset when the cummulative sum greater than another column value create table #reset_runn_total ( id int identity(1,1), val int, reset_val int, ...
Pரதீப்'s user avatar
2 votes
3 answers

Rolling count of total transactions over time

I need to get a set of total transactions over time on a weekly interval. Essentially I need a total-transactions-to-date column. When I group by WEEK(Date) I get the amount of transactions for that ...
damian's user avatar
  • 123
6 votes
1 answer

Calculate Quantity Based on First in, First Out (FIFO)

I'm trying to get result of quantity based on FIFO, with 2 tables below: Table Purchase: | PO | Date | Quantity | Item | |-------|--------------|----------|------| | PO001 | 01-Jan-2016 ...
Mei_R's user avatar
  • 63
5 votes
2 answers

Set non-negative floor for rolling sum, in SQL Server

I need to set a floor on the rolling sum calculation. For example, with PKID NumValue GroupID ---------------------------- 1 -1 1 2 -2 1 3 5 1 4 ...
Ryan's user avatar
  • 313
2 votes
1 answer

Calculating Running Total After Reset

I have a SQL Server 2012 table which has customer id, amount, and a reset columns. I’m trying to calculate the running total and also calculate the running total after reset. Once the reset "flag" is ...
user20907's user avatar
  • 173
1 vote
2 answers

Sum all unique values from previous dates

Let's say, for simplicity sake, I have the following table: id amount p_id date ------------------------------------------------ 1 5 1 2020-01-01T01:00:00 2 10 ...
tony's user avatar
  • 13