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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with query

Re: Help with query

From: Phil Lawrence <prlawrence_at_gmail.com>
Date: 23 Jan 2007 14:54:35 -0800
Message-ID: <1169592875.000734.68240@v45g2000cwv.googlegroups.com>


On Jan 23, 4:10 pm, "AZNewsh" <g..._at_dana.ucc.nau.edu> wrote:

> ID-------Year--------Code------Date-------Action
> 1 2007 1234 1/1/07 A
> 1 2007 1234 1/2/07 B
> 1 2007 1234 1/3/07 C
> 1 2007 4321 1/6/07 A
> 1 2007 4321 1/7/07 C
> 1 2007 4321 1/8/07 B

> I want to identify where ACTION C occurs before Action B where the code
> is the same, in the example above only line 5 would satisfy that
> criteria since ID is the same, year is 2007 code was the same and the
> action C occured on a date before action B

SELECT id
  FROM table c
 WHERE year = '2007'
   AND action = 'C'
   AND exists

       (
         SELECT *
           FROM table b
          WHERE b.id = c.id
            AND b.code = c.code
            AND b.action = 'B'
            AND b.date > c.date
       )

--
Phil R Lawrence
Received on Tue Jan 23 2007 - 16:54:35 CST

Original text of this message

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