473,395 Members | 1,956 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,395 software developers and data experts.

multiple dates but within 24 hrs

Hi all,

just came across a reall tricky one, perhaps some smart cookie out there can
help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended them.

Now the problem is I want to find all the people that have the date/time
within 24 hours for patients that have been attended more than once.

now a simple duplicates query filters the single patients but then if I have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate then
query all the duplicates and cycle around to find any <24 datediff) but if
you think about this it gets mathematically complex very quickly with many
duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!
Nov 13 '05 #1
5 1456
To return the records where a UR has more than one record in 24 hours, you
could use a subquery such as this:

NearestRec:
(SELECT TOP 1 DT
FROM Table1 AS Dupe
WHERE (Dupe.UR = Table1.UR)
AND (DateDiff("n", Table1.DT, Table2.DT) < 1440)
AND (Dupe.ID <> Table1.ID)
ORDER BY Abs(Table1.DT - Dupe.DT), Dupe.ID)

That assumes:
- the table is named Table1;
- the date/time field is named DT.
- the primary key is named ID.

The DateDiff() limits it to those that have another record within 1440
minutes.
Sorting by the absolute value of the difference chooses the closest match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Hi all,

just came across a reall tricky one, perhaps some smart cookie out there
can help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended them.

Now the problem is I want to find all the people that have the date/time
within 24 hours for patients that have been attended more than once.

now a simple duplicates query filters the single patients but then if I
have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate
then query all the duplicates and cycle around to find any <24 datediff)
but if you think about this it gets mathematically complex very quickly
with many duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!

Nov 13 '05 #2
Thanks for that I'll try it now!

Al

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
To return the records where a UR has more than one record in 24 hours, you
could use a subquery such as this:

NearestRec:
(SELECT TOP 1 DT
FROM Table1 AS Dupe
WHERE (Dupe.UR = Table1.UR)
AND (DateDiff("n", Table1.DT, Table2.DT) < 1440)
AND (Dupe.ID <> Table1.ID)
ORDER BY Abs(Table1.DT - Dupe.DT), Dupe.ID)

That assumes:
- the table is named Table1;
- the date/time field is named DT.
- the primary key is named ID.

The DateDiff() limits it to those that have another record within 1440
minutes.
Sorting by the absolute value of the difference chooses the closest match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Hi all,

just came across a reall tricky one, perhaps some smart cookie out there
can help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended
them.

Now the problem is I want to find all the people that have the date/time
within 24 hours for patients that have been attended more than once.

now a simple duplicates query filters the single patients but then if I
have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate
then query all the duplicates and cycle around to find any <24 datediff)
but if you think about this it gets mathematically complex very quickly
with many duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!


Nov 13 '05 #3
Sorry call me stupid but I can't seem to work it out.

I tried something like this

select * from qry_MET_PATIENT_no_null_time_date,
(SELECT TOP 1 [Date of MET]
FROM qry_MET_PATIENT_duplicates AS Dupe
WHERE (Dupe.[UR Field] = qry_MET_PATIENT_no_null_time_date.UR)
AND (DateDiff("n", qry_MET_PATIENT_no_null_time_date.[Date of MET],
Table2.[Date of MET]) < 1440)
AND (Dupe.[UR Field] <> qry_MET_PATIENT_no_null_time_date.UR)
)

at I missing the point here?

Your help is greatly appreciated
Al


"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
To return the records where a UR has more than one record in 24 hours, you
could use a subquery such as this:

NearestRec:
(SELECT TOP 1 DT
FROM Table1 AS Dupe
WHERE (Dupe.UR = Table1.UR)
AND (DateDiff("n", Table1.DT, Table2.DT) < 1440)
AND (Dupe.ID <> Table1.ID)
ORDER BY Abs(Table1.DT - Dupe.DT), Dupe.ID)

That assumes:
- the table is named Table1;
- the date/time field is named DT.
- the primary key is named ID.

The DateDiff() limits it to those that have another record within 1440
minutes.
Sorting by the absolute value of the difference chooses the closest match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Hi all,

just came across a reall tricky one, perhaps some smart cookie out there
can help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended
them.

Now the problem is I want to find all the people that have the date/time
within 24 hours for patients that have been attended more than once.

now a simple duplicates query filters the single patients but then if I
have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate
then query all the duplicates and cycle around to find any <24 datediff)
but if you think about this it gets mathematically complex very quickly
with many duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!


Nov 13 '05 #4
Not exactly sure of your fields and matching, but did you have an ORDER BY
clause?

Sorting by the absolute difference of the date/time field and then choosing
the TOP 1 gives you the record that is the nearest match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Sorry call me stupid but I can't seem to work it out.

I tried something like this

select * from qry_MET_PATIENT_no_null_time_date,
(SELECT TOP 1 [Date of MET]
FROM qry_MET_PATIENT_duplicates AS Dupe
WHERE (Dupe.[UR Field] = qry_MET_PATIENT_no_null_time_date.UR)
AND (DateDiff("n", qry_MET_PATIENT_no_null_time_date.[Date of MET],
Table2.[Date of MET]) < 1440)
AND (Dupe.[UR Field] <> qry_MET_PATIENT_no_null_time_date.UR)
)

at I missing the point here?

Your help is greatly appreciated
Al
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
To return the records where a UR has more than one record in 24 hours,
you could use a subquery such as this:

NearestRec:
(SELECT TOP 1 DT
FROM Table1 AS Dupe
WHERE (Dupe.UR = Table1.UR)
AND (DateDiff("n", Table1.DT, Table2.DT) < 1440)
AND (Dupe.ID <> Table1.ID)
ORDER BY Abs(Table1.DT - Dupe.DT), Dupe.ID)

That assumes:
- the table is named Table1;
- the date/time field is named DT.
- the primary key is named ID.

The DateDiff() limits it to those that have another record within 1440
minutes.
Sorting by the absolute value of the difference chooses the closest
match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Hi all,

just came across a reall tricky one, perhaps some smart cookie out there
can help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended
them.

Now the problem is I want to find all the people that have the date/time
within 24 hours for patients that have been attended more than once.

now a simple duplicates query filters the single patients but then if I
have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate
then query all the duplicates and cycle around to find any <24 datediff)
but if you think about this it gets mathematically complex very quickly
with many duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!

Nov 13 '05 #5
Yes I tried but I think I'm missing the point with the subquery.

I'll go and do some reading about it as I'm obviusly not great on my SQL.

Thanks for your help

Al
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Not exactly sure of your fields and matching, but did you have an ORDER BY
clause?

Sorting by the absolute difference of the date/time field and then
choosing the TOP 1 gives you the record that is the nearest match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Sorry call me stupid but I can't seem to work it out.

I tried something like this

select * from qry_MET_PATIENT_no_null_time_date,
(SELECT TOP 1 [Date of MET]
FROM qry_MET_PATIENT_duplicates AS Dupe
WHERE (Dupe.[UR Field] = qry_MET_PATIENT_no_null_time_date.UR)
AND (DateDiff("n", qry_MET_PATIENT_no_null_time_date.[Date of
MET], Table2.[Date of MET]) < 1440)
AND (Dupe.[UR Field] <> qry_MET_PATIENT_no_null_time_date.UR)
)

at I missing the point here?

Your help is greatly appreciated
Al
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
To return the records where a UR has more than one record in 24 hours,
you could use a subquery such as this:

NearestRec:
(SELECT TOP 1 DT
FROM Table1 AS Dupe
WHERE (Dupe.UR = Table1.UR)
AND (DateDiff("n", Table1.DT, Table2.DT) < 1440)
AND (Dupe.ID <> Table1.ID)
ORDER BY Abs(Table1.DT - Dupe.DT), Dupe.ID)

That assumes:
- the table is named Table1;
- the date/time field is named DT.
- the primary key is named ID.

The DateDiff() limits it to those that have another record within 1440
minutes.
Sorting by the absolute value of the difference chooses the closest
match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Baldy" <Jo**@smith.com> wrote in message
news:41**********@news.adelaide.pipenetworks.com.. .
Hi all,

just came across a reall tricky one, perhaps some smart cookie out
there can help.

I'm querying patient data from our hospital it might look like this

UR Date arrival time
429784 27/01/2004 16:04
421685 25/07/2003 19:35
421685 24/07/2003 12:47
427670 23/07/2004 19:45
430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30
431563 13/06/2004 14:16
432121 12/08/2004 19:48

(sorry in Australia our date are dd/mm/yyyy )
first column is the patient ID (UR) (de-identified so not a real UR for
here) the second is the date & time that the emergency team attended
them.

Now the problem is I want to find all the people that have the
date/time within 24 hours for patients that have been attended more
than once.

now a simple duplicates query filters the single patients but then if I
have

430163 4/03/2004 17:25
430163 20/02/2004 22:30
430163 20/02/2004 2:16
430163 5/03/2004 20:30

clears I can see that this person has been attended 4 times and 2 times
within 24 hours.

BUT! how do I simply query this without going mad! I could write a VBA
function to do a comparison for each duplicate (ie find each duplicate
then query all the duplicates and cycle around to find any <24
datediff) but if you think about this it gets mathematically complex
very quickly with many duplicates ( O^n maybe?)

Can anyone come up with a more simple solution maybe.

A good homework question perhaps?

Baldy!


Nov 13 '05 #6

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

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...
9
by: Gleep | last post by:
sorry i didn't explain it correctly before my table is like this example fields: ID name username outcome date1 date2 date3 (etc..) - date15 price1 price2 price3 (etc..) I know that...
3
by: RC | last post by:
I am try test a simple HTML form with PHP <form method=POST action="testing.php"> Cat <input type="checkbox" name="pet" value="cat"> Dog <input type="checkbox" name="pet" value="dog"> Pig...
2
by: DaveDiego | last post by:
I'm building a report that has a count of cases for employees. I have separate queries that count, OpenCases, NewCases, TotalCases, Etc. I would like to put all those counts into a record for each...
0
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11...
4
by: Matt Hamilton | last post by:
I have a query that returns multiple dates and I want to find the average date... How can I do this? I tried to use the ToOADate() to get the total of the dates as a double, then divide by the...
1
by: josecruz | last post by:
I have to create a summary report that will provide counts and # average of days for multiple "Status" by entering different dates for every criteria. I have created several queries that calculates...
3
by: psuaudi | last post by:
I am trying to use the following code, but I think there is an error in my syntax: Count = DCount("", "Change Dates", " = '" & !! & "' AND CVDate(Int( #" & & "# )) = #" & (Date) & "#") I...
7
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database....
4
by: dawanwan | last post by:
I built a database at my job for tracking and reporting debt records. I am very new at using Access and have basically trained myself. Here's my problem: I created a parameter query using a form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.