473,465 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rolling sum question

I am trying to write a query/report where I can come up with a rolling
sum of the past five days for each line item that I have.

For example:

Transaction Date Amount
15-Jan-06 ($5.50)
17-Jan-06 ($2.00)
18-Jan-06 ($3.75)
23-Jan-06 ($2.00)
26-Jan-06 ($2.00)
27-Jan-06 ($1.75)
29-Jan-06 ($3.50)
30-Jan-06 ($5.25)
31-Jan-06 ($1.75)
01-Feb-06 ($2.00)
03-Feb-06 ($1.75)
05-Feb-06 ($1.75)
09-Feb-06 ($3.75)
10-Feb-06 ($5.50)
11-Feb-06 ($10.50)
12-Feb-06 ($1.75)
15-Feb-06 ($1.75)
20-Feb-06 ($1.75)
22-Feb-06 ($2.00)
24-Feb-06 ($1.75)

So that I would have a column where, for example, for 30-Jan-06, I
would have the sum of the values from 26-Jan to 30-Jan.

Any help would be greatly appreciated!

Jun 4 '06 #1
3 2955
"none" <rw*******@yahoo.com> wrote in
news:11**********************@f6g2000cwb.googlegro ups.com:
I am trying to write a query/report where I can come up with a
rolling sum of the past five days for each line item that I
have.

For example:

Transaction Date Amount
15-Jan-06 ($5.50)
17-Jan-06 ($2.00)
18-Jan-06 ($3.75)
23-Jan-06 ($2.00)
26-Jan-06 ($2.00)
27-Jan-06 ($1.75)
29-Jan-06 ($3.50)
30-Jan-06 ($5.25)
31-Jan-06 ($1.75)
01-Feb-06 ($2.00)
03-Feb-06 ($1.75)
05-Feb-06 ($1.75)
09-Feb-06 ($3.75)
10-Feb-06 ($5.50)
11-Feb-06 ($10.50)
12-Feb-06 ($1.75)
15-Feb-06 ($1.75)
20-Feb-06 ($1.75)
22-Feb-06 ($2.00)
24-Feb-06 ($1.75)

So that I would have a column where, for example, for
30-Jan-06, I would have the sum of the values from 26-Jan to
30-Jan.

Any help would be greatly appreciated!

Use a subquery that gets the sum,

SELECT [Transaction Date], Amount, (SELECT Sum(Amount) from
Table as Sub Where Sub.[Transaction Date] between Main.
[Transaction date]-5 And Main.[Transaction Date]) as Main;

--
Bob Quintal

PA is y I've altered my email address.
Jun 5 '06 #2
Sorry for the ignorance ... I've never used subqueries before.

So, if I have a query that reads as:

SELECT TransactionHistory.[Transaction Date],
Sum(TransactionHistory.Amount) AS SumOfAmount
FROM TransactionHistory
GROUP BY TransactionHistory.[Transaction Date];

where would I put the subquery code below?

Thanks!

Bob Quintal wrote:
"none" <rw*******@yahoo.com> wrote in
news:11**********************@f6g2000cwb.googlegro ups.com:
I am trying to write a query/report where I can come up with a
rolling sum of the past five days for each line item that I
have.

For example:

Transaction Date Amount
15-Jan-06 ($5.50)
17-Jan-06 ($2.00)
18-Jan-06 ($3.75)
23-Jan-06 ($2.00)
26-Jan-06 ($2.00)
27-Jan-06 ($1.75)
29-Jan-06 ($3.50)
30-Jan-06 ($5.25)
31-Jan-06 ($1.75)
01-Feb-06 ($2.00)
03-Feb-06 ($1.75)
05-Feb-06 ($1.75)
09-Feb-06 ($3.75)
10-Feb-06 ($5.50)
11-Feb-06 ($10.50)
12-Feb-06 ($1.75)
15-Feb-06 ($1.75)
20-Feb-06 ($1.75)
22-Feb-06 ($2.00)
24-Feb-06 ($1.75)

So that I would have a column where, for example, for
30-Jan-06, I would have the sum of the values from 26-Jan to
30-Jan.

Any help would be greatly appreciated!

Use a subquery that gets the sum,

SELECT [Transaction Date], Amount, (SELECT Sum(Amount) from
Table as Sub Where Sub.[Transaction Date] between Main.
[Transaction date]-5 And Main.[Transaction Date]) as Main;

--
Bob Quintal

PA is y I've altered my email address.


Jun 5 '06 #3
"none" <rw*******@yahoo.com> wrote in
news:11**********************@i39g2000cwa.googlegr oups.com:
Sorry for the ignorance ... I've never used subqueries before.

So, if I have a query that reads as:

SELECT TransactionHistory.[Transaction Date],
Sum(TransactionHistory.Amount) AS SumOfAmount
FROM TransactionHistory
GROUP BY TransactionHistory.[Transaction Date];

where would I put the subquery code below?

Thanks!
SELECT main.[Transaction Date],
Sum(main.Amount) as SumofAmount,
(SELECT Sum(sub.Amount)
from TransactionHistory alias Sub
Where Sub.[Transaction Date]
between Main.[Transaction date]-5
And Main.[Transaction Date])
FROM TransactionHistory alias Main
Group by main.[transaction date];

Bob Quintal wrote:
"none" <rw*******@yahoo.com> wrote in
news:11**********************@f6g2000cwb.googlegro ups.com:
> I am trying to write a query/report where I can come up with a > rolling sum of the past five days for each line item that I
> have.
>
> For example:
>
> Transaction Date Amount
> 15-Jan-06 ($5.50)
> 17-Jan-06 ($2.00)
> 18-Jan-06 ($3.75)
> 23-Jan-06 ($2.00)
> 26-Jan-06 ($2.00)
> 27-Jan-06 ($1.75)
> 29-Jan-06 ($3.50)
> 30-Jan-06 ($5.25)
> 31-Jan-06 ($1.75)
> 01-Feb-06 ($2.00)
> 03-Feb-06 ($1.75)
> 05-Feb-06 ($1.75)
> 09-Feb-06 ($3.75)
> 10-Feb-06 ($5.50)
> 11-Feb-06 ($10.50)
> 12-Feb-06 ($1.75)
> 15-Feb-06 ($1.75)
> 20-Feb-06 ($1.75)
> 22-Feb-06 ($2.00)
> 24-Feb-06 ($1.75)
>
> So that I would have a column where, for example, for
> 30-Jan-06, I would have the sum of the values from 26-Jan to > 30-Jan.
>
> Any help would be greatly appreciated!
>

Use a subquery that gets the sum,

SELECT [Transaction Date], Amount, (SELECT Sum(Amount) from
Table as Sub Where Sub.[Transaction Date] between Main.
[Transaction date]-5 And Main.[Transaction Date]) as Main;

--
Bob Quintal

PA is y I've altered my email address.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Adi | last post by:
Hi, I have a web application (using J2EE) which runs on 3 tomcats (4.0) for Load Balancing. I have recently started to use the Log4j in this application. Currently the logs for this application...
5
by: traga_2_whiskys | last post by:
Weel i want do make a box with text rolling down to up, i've make-it wiht <marquee> in html, byt the text isn't always rolling. can anibody help me?
4
by: elake | last post by:
I have an application that creates a lot of large log files. I only want to keep logs for the previous 4 months. I am looking for a way to list the contents of the log dir and if the create date on...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: Jose Durazo | last post by:
Hello, I'm doing an exercise to simulate rolling a pair of dice 36,000 times, then count and display how many times the simulation rolls each possible sum. For some reason each time I run my...
3
by: farhadtarapore | last post by:
I have a very large C++ application that has been converted into a windows service. This application writes a lot of statements to the console i.e. cout and cerr. I have used std::ofstream...
4
by: brendan.wong | last post by:
hello. i'm trying to incorporate error handling into my application, but i've run into a dilemma. i've already performed 10 successful INSERTS, but on the 11th INSERT, the application fails for...
2
by: cowboyjeff05 | last post by:
the question is 1) build a Die class (6 sided). Then create a driver that tests your class. Start with one die in your driver then add a second die and notify the user and count when he or she rolls...
1
by: Shark2026 | last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it. In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.