Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Help me compare fields in two distinct records

Help me compare fields in two distinct records

From: Peter Hazelton <peterhazelton_at_hotmail.com>
Date: Mon, 14 Aug 2000 16:54:33 GMT
Message-Id: <10589.114512@fatcity.com>


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

where icons IN (602, 610)
    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



Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com Received on Mon Aug 14 2000 - 11:54:33 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US