Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Problem
"MAB" <bad-email_at_nowhere.com> wrote in message
news:34bv4uF474jt4U1_at_individual.net...
> I'm using 9i DB. I have table Ledger with pri. key Ledger_id, It has say
two
> other fields Customer_ID and Transaction_Type_id. Now ofcourse the other
two
> are not unique. What I want is to find all records with
transaction_type_id
> = 4 with the condition that the previous transaction_type_id is 92 and one
> before the previous is 24 for the same customer_id ( the customer_id
should
> be the same)
>
> So for example
>
> Ledger_id Customer_id Transaction_type_id
>
> 1 1 1
> 2 1 24
> 3 2 5
> 4 1 92
> 5 3 16
> 6 1 4
>
>
> You can see that ledger_id # 6 is the record my query should bring because
> it has ( for customer_id 1)
>
> 1. Transaction_type_id = 4
> 2. previous TTI = 92
> 3 2nd Last TTI = 24
>
> so it meets all conditions.
> What would be the sql query that would bring all such records which meet
the
> above conditions
>
> thx.
>
>
I can give you a hint. You will have experiment with lead , lag analytical functions to get the result. Received on Sun Jan 09 2005 - 01:17:47 CST
![]() |
![]() |