Compare current record to previous record

G

Guest

I am using Office 2003 on Windows XP.

I need a SQL string that selects records from a table (
) such that
the [High_Balance] for today ([Run_Date]) is greater than the [Low_Balance]
as recorded in the previous day's record ([Run_Date] minus one day) for each
[Acct_Number] in the
.

This should yield a list of [Acct_Number]'s where today's high balance is
greater than yesterday's low balance.

Can someone please help me out on this one?

Many thanks in advance.
 
G

giorgio rancati

Hi, quartz
if I understood well .....
----
SELECT T1.*
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
WHERE T1.High_Balance>T2.Low_Balance
 
G

Guest

Thanks Giorgio,

Only, shouldn't [Acct_Number] figure into the SQL somewhere? I only want to
compare like accounts...how would that be included?

giorgio rancati said:
Hi, quartz
if I understood well .....
----
SELECT T1.*
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
WHERE T1.High_Balance>T2.Low_Balance
----

Bye
Giorgio

quartz said:
I am using Office 2003 on Windows XP.

I need a SQL string that selects records from a table (
) such that
the [High_Balance] for today ([Run_Date]) is greater than the [Low_Balance]
as recorded in the previous day's record ([Run_Date] minus one day) for each
[Acct_Number] in the
.

This should yield a list of [Acct_Number]'s where today's high balance is
greater than yesterday's low balance.

Can someone please help me out on this one?

Many thanks in advance.
 
G

giorgio rancati

ops..
I forgot [Acct_Number]

----
SELECT T1.*,T2.Low_Balance AS Yesterday_Low_Balace
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
AND T1.Acct_Number=T2.Acct_Number
WHERE T1.High_Balance>T2.Low_Balance
----


Bye
Giorgio

quartz said:
Thanks Giorgio,

Only, shouldn't [Acct_Number] figure into the SQL somewhere? I only want to
compare like accounts...how would that be included?

giorgio rancati said:
Hi, quartz
if I understood well .....
----
SELECT T1.*
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
WHERE T1.High_Balance>T2.Low_Balance
----

Bye
Giorgio

quartz said:
I am using Office 2003 on Windows XP.

I need a SQL string that selects records from a table (
) such that
the [High_Balance] for today ([Run_Date]) is greater than the [Low_Balance]
as recorded in the previous day's record ([Run_Date] minus one day)
for
each
[Acct_Number] in the
.

This should yield a list of [Acct_Number]'s where today's high balance is
greater than yesterday's low balance.

Can someone please help me out on this one?

Many thanks in advance.
 
G

Guest

Thanks much Giorgio, I will give this a try tomorrow when I return to work!

giorgio rancati said:
ops..
I forgot [Acct_Number]

----
SELECT T1.*,T2.Low_Balance AS Yesterday_Low_Balace
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
AND T1.Acct_Number=T2.Acct_Number
WHERE T1.High_Balance>T2.Low_Balance
----


Bye
Giorgio

quartz said:
Thanks Giorgio,

Only, shouldn't [Acct_Number] figure into the SQL somewhere? I only want to
compare like accounts...how would that be included?

giorgio rancati said:
Hi, quartz
if I understood well .....
----
SELECT T1.*
FROM Tables AS T1
INNER JOIN
Tables AS T2 ON T1.Run_Date-1=T2.Run_Date
WHERE T1.High_Balance>T2.Low_Balance
----

Bye
Giorgio

"quartz" <[email protected]> ha scritto nel messaggio
I am using Office 2003 on Windows XP.

I need a SQL string that selects records from a table (
) such that
the [High_Balance] for today ([Run_Date]) is greater than the
[Low_Balance]
as recorded in the previous day's record ([Run_Date] minus one day) for
each
[Acct_Number] in the
.

This should yield a list of [Acct_Number]'s where today's high balance is
greater than yesterday's low balance.

Can someone please help me out on this one?

Many thanks in advance.
 

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