how to extract the nearest matched data from a table

H

Headache

Hi. I am a new user of Access 2003.
Here I have a problem. I have thought it for 2 days. So far I did not
sort it out.
The question is how to extract the nearst matched data from a table.
For example, I have 2 tables
Table A
Time(A) Price
09:10 10
09:15 15
09:18 18
.. .
.. .
.. .
.. .

Table B
Time(B)
09:10
09:13
09:16
..
..
..
..
..
I want to extract all the values in Price field when Time(A)<=Time(B)
and Time(B)-Time(A) is maximum.

I am a non-English speaker. So hopefully you can understand it.
Thanks
 
C

Chris M

Headache said:
Hi. I am a new user of Access 2003.
Here I have a problem. I have thought it for 2 days. So far I did not
sort it out.
The question is how to extract the nearst matched data from a table.
For example, I have 2 tables
Table A
Time(A) Price
09:10 10
09:15 15
09:18 18
. .
. .
. .
. .

Table B
Time(B)
09:10
09:13
09:16
.
.
.
.
.
I want to extract all the values in Price field when Time(A)<=Time(B)
and Time(B)-Time(A) is maximum.

I am a non-English speaker. So hopefully you can understand it.
Thanks

Hi, Sorry, probably just me being thick, but please could you clarify what
you are asking for.

Did you mean 'and TimeB - TimeA is MINIMUM.

ie you are looking for the price that has a time closest (but before) the
time in table B?

Cheers,

Chris.
 
C

Chris M

Chris M said:
Hi, Sorry, probably just me being thick, but please could you clarify
what you are asking for.

Did you mean 'and TimeB - TimeA is MINIMUM.

ie you are looking for the price that has a time closest (but before) the
time in table B?

Cheers,

Chris.

On the basis that my assumption was true, does this help?

select * from TableB,TableA
where TableA.Time >= TableB.Time
and not exists
(
select 1
from TableA as TA2
where TA2.Time < TableA.Time
and TA2.Time >= TableB.Time
)

So we are saying display TableA and TableB where timeB <= TimeA. And there
are no records in TableA with a lower time that is still higher than the
TableB time.

Cheers,

Chris.

:)
 
H

Headache

Chris said:
On the basis that my assumption was true, does this help?

select * from TableB,TableA
where TableA.Time >= TableB.Time
and not exists
(
select 1
from TableA as TA2
where TA2.Time < TableA.Time
and TA2.Time >= TableB.Time
)

So we are saying display TableA and TableB where timeB <= TimeA. And there
are no records in TableA with a lower time that is still higher than the
TableB time.

Cheers,

Chris.

:)

Yes, it is minimum. Thanks a lot.
 

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