473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

query needed to subtract values

vnl
I need to create a report or field that will show the difference between a
customer's balance on two different dates for every customer in our
database (for example, see below: I need the difference between customer
001's balance on 1/1/03 and their balance on 2/1/03). I have the following
types of information in a single table:

Customer_ID Date Balance
1 1/1/03 $50
1 2/1/03 $55
1 3/1/03 $75
1 4/1/03 $100
2 1/1/03 $10
2 2/1/03 $19
2 3/1/03 $52
2 4/1/03 $25

I need to automate the calculation because there are thousands of entries.
Any idea how to do this?

Thanks.

Nov 13 '05 #1
2 1359
On Mon, 02 Aug 2004 18:14:11 -0500, vnl <vn****@vnl999.invalid> wrote:

Here is one solution. Note that I took the liberty to rename your
fields. Date is a reserved word, so I don't like to use it as a field
name.

SELECT T1.Customer_ID, T1.BalanceDate, T1.BalanceAmount, (Select
BalanceAmount from tblCustomerBalance T2 where
Customer_ID=T1.Customer_ID and T2.BalanceDate=(select Min(BalanceDate)
from tblCustomerBalance T3 where T3.BalanceDate>T1.BalanceDate)) AS
NextAmount, [BalanceAmount]-[NextAmount] AS Difference
FROM tblCustomerBalance AS T1;

-Tom.

I need to create a report or field that will show the difference between a
customer's balance on two different dates for every customer in our
database (for example, see below: I need the difference between customer
001's balance on 1/1/03 and their balance on 2/1/03). I have the following
types of information in a single table:

Customer_ID Date Balance
1 1/1/03 $50
1 2/1/03 $55
1 3/1/03 $75
1 4/1/03 $100
2 1/1/03 $10
2 2/1/03 $19
2 3/1/03 $52
2 4/1/03 $25

I need to automate the calculation because there are thousands of entries.
Any idea how to do this?

Thanks.


Nov 13 '05 #2
Hi,
If you have records for each date that is super cool...

SELECT a.CustomerID, a.Date, a.Balance-b.Balance
FROM myTable As a LEFT JOIN myTable As b
ON b.date= a.date-1 AND a.CustomerID=b.CustomerID
The idea is to get two references to the same data, but for the same client,
"b" is one day in the past, in relation with the data in "a".

Hoping it may help,
Vanderghast, Access MVP

"vnl" <vn****@vnl999.invalid> wrote in message
news:Xn********************@216.196.97.131...
I need to create a report or field that will show the difference between a
customer's balance on two different dates for every customer in our
database (for example, see below: I need the difference between customer
001's balance on 1/1/03 and their balance on 2/1/03). I have the following
types of information in a single table:

Customer_ID Date Balance
1 1/1/03 $50
1 2/1/03 $55
1 3/1/03 $75
1 4/1/03 $100
2 1/1/03 $10
2 2/1/03 $19
2 3/1/03 $52
2 4/1/03 $25

I need to automate the calculation because there are thousands of entries.
Any idea how to do this?

Thanks.

Nov 13 '05 #3

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

Similar topics

5
by: Got2Go | last post by:
Hello Group, I have a table that has 3 columns: ID (int), datetime, Value(varchar) ID = ID for the SNMP device datetime = time record was added value = value added for that device. This...
5
by: Got2Go | last post by:
Hello Group, I have a table that has 3 columns: ID (int), datetime, Value(varchar) ID = ID for the SNMP device datetime = time record was added value = value added for that device. This...
7
by: Techhead | last post by:
I have a date/time field with a sql format of "datetime" The actual date/time data format is MM/DD/YYYY^hh:mm:ss:pm or "1/25/2007 12:00:16 AM" Both the date and time are combined on the same field...
7
by: Ecohouse | last post by:
I'm working on a project that was dropped in my lap. It is in Access 2003. There are short time fields which get calculated values (eg. 1:30). But I will need to total up those values for...
1
by: Orbie | last post by:
Hi All, I'm new to VB.NET and i'm looking for some help with my Windows Form. I need to check if a Commodity entered into (TextBox1.Text) already exists on my table before i insert it. I'm having...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.