Query last customer balance

C

Chris

I have an access table that stores a customer's balance for xx months. I
want to run a query that will pull the last month's balance. However, one
accounts last balance could be in December while another accounts last
balance could be in February. I just want to pull the Last balance and month
for each account.
 
D

Dirk Goldgar

Chris said:
I have an access table that stores a customer's balance for xx months. I
want to run a query that will pull the last month's balance. However, one
accounts last balance could be in December while another accounts last
balance could be in February. I just want to pull the Last balance and
month
for each account.


Suppose you have a table like this:

AccountBalances
------------------------
AccountNo (primary key)
BalanceDate (date/time)
BalanceAmount (currency)

Then you query could be something like this:

SELECT AccountNo, BalanceDate, BalanceAmount
FROM AccountBalances
WHERE AccountBalances.BalanceDate=
(SELECT Max(T.BalanceDate) FROM AccountBalances T
WHERE T.AccountNo = AccountBalances.AccountNo);

That's "air SQL", but something along those lines should do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top