Questions tagged [cumulative-sum]

For questions regarding implementations or algorithms for calculating cumulative sums (also known as running totals). Always add the tag for the language/platform!

A cumulative sum (also known as a running total or partial sum) refers to the concept of maintaining only a single value (the sum), which is updated each time a new value is added to the sequence.

1433 questions
-1
votes
1 answer

Cummulative Dictionary

I am trying to write a python function where for each key (the dates), the value would be the sum of that day's result and the previous day(s) (sort of following the same logic as the fibonacci sequence). For example, I have: {20200516: {'Level1':…
-1
votes
3 answers

How does Oracle calculate the running total just by using order by clause?

I'm very confused in trying to understand how SQL calculates the running total with just using "order by" clause and nothing else. There is no counter or increment happening in the query. Can anyone help me understand how detail it works at the data…
user4931155
-1
votes
1 answer

fetching data from cumulative-sum table

This is my main table which stores keyword impressions according to dates. +---------+-----------+------------+-------------+ | ID | KeywordId | ReportDate | Impressions | +---------+-----------+------------+-------------+ | 3324620 | 969274443…
Burc Hasergin
  • 449
  • 1
  • 4
  • 6
-1
votes
1 answer

I Need Account Statement Table in PHP and SQL

Please, I need expert help. I am new here. I want to display a table that will show the Balance = Amount - Cost as shown below, but the table should be reducing the amount based on the cost deducted. Table one is what I got from my code, the first…
Abraham
  • 1
  • 2
-1
votes
1 answer

Running total. CTE keeps running after the result has been fetched

Spent a few hours trying to debug the query and understand why it keeps scanning the whole table after the result has been fetched. The query calculates the running total and should stop execution as soon as the limit is reached or exceeded.…
Evgeny Belov
  • 308
  • 4
  • 12
-1
votes
1 answer

Which function allow me to calculate cumulative variance over a vector?

I need to calculate the cumulative variance of a vector. I have tried to build and script, but this script takes too much time to calculate the cumulative variance of my vectors of size 1*100000. Do you know if there exists a faster way to find this…
JuanMuñoz
  • 165
  • 2
  • 11
-1
votes
1 answer

How can I get the number of rows within a certain periodo for each row in PostgreSQL?

I have a table in PostgreSQL and I'd like to get, for each row, the number of rows that are within a period if 30 days before the date of each row (including the event of the row at each moment). Example: Event. Date A. …
belfastcowboy24
  • 147
  • 2
  • 7
-1
votes
1 answer

Calculate Running total of active users by groups

I need to find the running total of active users in the system based on the groups If a user is currently suspended he shouldn't be considered in the current count but should be considered when he was active For Ex A user got suspended in april…
-1
votes
1 answer

SQL - Aggregation between two string rows

I have a following table in which I have employee's transactions having salary as Code 'S' in it: Id | Code | Amount | Date 1 | B | 40 | 2017-01-01 1 | S | 45000 | 2017-01-02 1 | D | 30000 | 2017-01-15 1 | B | 15000 |…
user1584253
  • 975
  • 2
  • 18
  • 55
-1
votes
1 answer

SQL RUNNING SUM TWO TABLES

I have two tables, orders and stock, I need to fill the order with the stock available, but can I make a running sum works CREATE TABLE `PEDIDOS` ( `N_PEDIDO` INTEGER, `COD_MATERIAL` INTEGER, `CAJAS_PEDIDOS` INTEGER ) CREATE TABLE `STOCK` (…
-1
votes
1 answer

How can I subtract from a running total subquery in my query?

I'm trying to create a case where if there's a previous payment I can deduct it from the selected amount date range. I've created everything I need except the previous payment amounts. I keep running into subquery errors SELECT acctnmbr …
Nick
  • 155
  • 4
  • 16
-1
votes
1 answer

Cumulative sum problem considering data till last record with multiple IDs

I have a dataset with multiple IDs and dates where I have created a column for Cumulative supply in python. My data is as follows SKU Date Demand Supply Cum_Supply 1 20160207 6 2 2 1 20160214 5 0 2 1 20160221 1 …
Neil S
  • 229
  • 7
  • 20
-1
votes
2 answers

Resetting Running Total based on value in another column per customerID - SQL Server

I've already tried looking on here for the answer to this question, and although have found similar queries, I haven't found this exact one. I'm looking to count the instances of a customer getting a certain score, and if they get less than that…
Amar
  • 37
  • 7
-1
votes
1 answer

using data.table to create sequence from starting points and increments

I would like to use data.table to repeatedly add an increment to a starting point. library(data.table) dat <- data.table(time=seq(from=as.POSIXct("2018-01-01 01:00:01"),to=as.POSIXct("2018-01-01 01:00:10"), by="secs"),…
bumblebee
  • 1,116
  • 8
  • 20
-1
votes
1 answer

keeping a running total of the values in a dictionary

I want the user to pick an item from the shop and I want to use a loop to keep track of the prices(the value in the dictionary) to add up and keep a running total after every input from user. If the user inputs something that is not in the…