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 -> SQL Problem

SQL Problem

From: MAB <bad-email_at_nowhere.com>
Date: Sun, 9 Jan 2005 10:52:30 +0500
Message-ID: <34bv4uF474jt4U1@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. Received on Sat Jan 08 2005 - 23:52:30 CST

Original text of this message

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