473,406 Members | 2,710 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,406 software developers and data experts.

DATE COMPARISON How to compare records on two tables

Hello everyone, I´m starting to learn Access , SQL and a bit of VB.

My problem is the following: I have two tables, one of them contains the records for missing points on a GPS system (called the "missing" table) ... the second table, contains all the available points on GPS (called the "complete" table). I will put an example

Table: Missing

Field1:Hour
----------------
10:04
10:09

Table2: GPS

Field1:X Field2:Y Field3:Hour
----------- ------------ -----------------
10 20 10:01
11 23 10:02
12 18 10:03
14 20 10:05
13 20 10:06
14 22 10:07
16 21 10:11


What I need to do is the following: go to each record on the "Missing" table and look for the record that is closer so to assign the values of Field1 and Field 2. to it. For example, lets look at the firs registry on table "missing" which is 10:04 .... on the GPS table i can found that there are two records that are close to 10:04, 10:03 and 10:05 ... so i want to average the values of the fields X and Y, and asign that average to a new fields on the missing tables as "AvgX" and "Avg"Y ... on this case it would turn out with the values of 13 for AvgX (average of 12 and 14) and 19 for AvgY (average of 18 and 20), like this:


Table: Missing

Field1:Hour Field2:AvgX Field3:AvgY
---------------- ----------------- -----------------
10:04 13 19



I was hoping to find a way to do it with sql queries, but i cant seem to find a way to compare between records, or the only choice is VB? in the case its VB, could somebody please guide me on same basic code i can apply?

thanks in advance,
Jul 11 '07 #1
5 2376
kepston
97 Expert
While I work on this, I have a couple of questions.

Will you accept fractions?
e.g. your second missing example is 10:09 producing X=15, Y=21.5

What result do you want if the missing time is not exactly half way between known points?
e.g. what values for 10:10? The same as 10:09, or higher, if higher, by 'distance' covered (linear interpolation).
Jul 12 '07 #2
While I work on this, I have a couple of questions.

Will you accept fractions?
e.g. your second missing example is 10:09 producing X=15, Y=21.5

What result do you want if the missing time is not exactly half way between known points?
e.g. what values for 10:10? The same as 10:09, or higher, if higher, by 'distance' covered (linear interpolation).

1. Thanks for your help!


2. regard your questions:

a. I accept fractions, there is no problem with that, in fact the data i put as an example was an integer approximation, in fact almost all the coordinates are numbers with fractions, but I put it on integer to simplify it.

b. If the missing time is not exactly half way between known points , then what it would be great is to have the most proximate point to the missing point. Originally i thought of linear interpolation as you said it .... for example:

if the missing point is 10:10 and I have as choices 10:07 and 10:11 ... I think there could be two choices: picking 10:11 because its nearer or making a linear interpolation using 10:07 and 10:11 ..... I believe the first choice is better because for this problem, one minute is really a huge difference, so taking an interpolation might produce a point pretty far away from an approximate point .... but either solution is good, so if you want to try any of this versions is excellent for me ....

again thanks, i appreciate your interest in helping me
Jul 12 '07 #3
kepston
97 Expert
if the missing point is 10:10 and I have as choices 10:07 and 10:11 ... I think there could be two choices: picking 10:11 because its nearer or making a linear interpolation using 10:07 and 10:11 ..... I believe the first choice is better because for this problem, one minute is really a huge difference, so taking an interpolation might produce a point pretty far away from an approximate point .... but either solution is good, so if you want to try any of this versions is excellent for me ....
I think you have misunderstood interpolation.
If we look at finding position at 10:10, then position at 10:11 would be better than at 10:07, using nearest known position.
Position at 10:11 would also be better than the average, which in this case would be position at 10:09. i.e. 2 minutes away from known!
Interpolation works out how far between start and end, required point is, and calculates for that position.
10:11-10:07 =4
10:10-10:07 =3
so we calculate position 3/4 of distance from position at 10:07 to 10:11.

(This will be accurate in a two dimensional space at constant speed and direction)
Jul 12 '07 #4
I think you have misunderstood interpolation.
If we look at finding position at 10:10, then position at 10:11 would be better than at 10:07, using nearest known position.
Position at 10:11 would also be better than the average, which in this case would be position at 10:09. i.e. 2 minutes away from known!
Interpolation works out how far between start and end, required point is, and calculates for that position.
10:11-10:07 =4
10:10-10:07 =3
so we calculate position 3/4 of distance from position at 10:07 to 10:11.

(This will be accurate in a two dimensional space at constant speed and direction)
I see, i was misunderstandig interpolation, i thought it was more like a weighted average ....
anyway, i think what it would fit best would be choosing , as you said, the nearest point from the missing one, also because i least i can guarantee that the point really exists.
Jul 12 '07 #5
kepston
97 Expert
I see, i was misunderstandig interpolation, i thought it was more like a weighted average ....
anyway, i think what it would fit best would be choosing , as you said, the nearest point from the missing one, also because i least i can guarantee that the point really exists.
Choosing an actual point makes sense.
In which case, do you want the point before, or after, or both when midway between known points?

qryNearestTime:
Expand|Select|Wrap|Line Numbers
  1. SELECT Missing.Hour AS MHour, Min(Abs([GPS].[Hour]-[mHour])) AS NearestTimeDiff,
  2. [mhour]-[nearestTimeDiff] AS Bef, [mhour]+[nearestTimeDiff] AS Aft
  3. FROM GPS, Missing
  4. GROUP BY Missing.Hour;
  5.  
qryNearestPoint:
Expand|Select|Wrap|Line Numbers
  1. SELECT [qryNearestTime].[MHour], [GPS].[Hour], [GPS].[X], [GPS].[Y]
  2. FROM qryNearestTime INNER JOIN GPS ON ([qryNearestTime].[Aft]=[GPS].[Hour]) 
  3. Or ([qryNearestTime].[Bef]=[GPS].[Hour]);
  4.  
qryNearestPoint will currently show both before and after when equidistant
Jul 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
2
by: Scott Knapp | last post by:
Good Day - I have a form which sets the current date, as follows: <script type="text/javascript"> xx=new Date() dd=xx.getDate() mm=xx.getMonth()+1 yy=xx.getYear() mmddyy=mm+"/"+dd+"/"+yy...
3
by: andrew | last post by:
Hi: I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member Key) . Thus I am sorting the records by...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
4
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
2
by: sparks | last post by:
I am trying to find valid records in a table but I must compare a date field to a date stored in the table I can see where this is wrong (ok I guess its not text) "= """ & Me.date & """" so...
7
by: matt | last post by:
hello, i have been given a challenging project at my org. i work on an inventory management web application -- keeping tracking of parts assigned to projects. in the past, i built an in-house...
5
by: Addy Smith | last post by:
I have 2 tables with different versions in access. Both are same but the latest version obviously has some new records and some deleted records from the previous version. How would I compare the new...
2
by: Louverril | last post by:
I have a problem I just can't get any sort of query findfirst or the sql below to correctly compare a value in a table with a supplied value. I created a very simple situation to try and figure ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.