Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Help me compare fields in two distinct records
Consider the following record set that is created by this SQL statement:
select icons,
to_char(admdatetime,'DD-MM-YYYY HH:MI:SS') ADMN, to_char(disdate,'DD-MM-YYYY HH:MI:SS') DIS, inptoutcome from inpatient
ICONS ADMN DIS INPTOUT --------- ------------------- ------------------- ------- 610 30-11-1997 10:19:00 08-12-1997 12:00:00 Home 610 08-04-1998 11:58:00 16-04-1998 12:00:00 Home 610 17-04-1998 07:04:00 29-04-1998 12:00:00 Acute 610 27-04-1998 03:26:00 30-04-1998 12:00:00 Home 602 25-03-1998 01:23:00 02-04-1998 12:00:00 Home 602 28-10-1998 07:58:00 29-10-1998 12:00:00 Home
I will be selecting a much larger record set when I run the query on my whole table so consider this a small test case.
What I need to do is compare the DIS time of one line to the ADMN time of the NEXT record when the ICONS numbers are the same.
i.e.
Consider the first two records in the data set. I need to see the difference
between line 2 ADMN of 08-04-1998 11:58:00 and line one DIS of 08-12-1997
12:00:00. These are obviously two different records so you can not do a
reqular SQL query on the two to find the difference.
So my question is: What is the best way to do this comparison? Array? Function? Proceedure? All or none of the above? If anyone can shed some light on this for me I would really appreciate it. My ultimate goal is to look at the data set and only select those records that have the same icons number and the difference between the DIS of line one and the ADM of line two is 24 hours or less.
Help me if you can, this list was tremendous for me last week in helping me with another problem so I anxiously await your response.
Peter Hazelton