Home » SQL & PL/SQL » SQL & PL/SQL » Instance Sequence Priority Values (Oracle 11g)
Instance Sequence Priority Values [message #610089] |
Mon, 17 March 2014 09:00 |
|
developer12
Messages: 88 Registered: July 2013
|
Member |
|
|
I have a list of sequences defined in Table A as:
seq instance
1 66
2 5
3 77
4 56
Now I have another Table B :
instance Value_a Value_b
77 10001 10002
88 10001 10001
4 10003 10004
Now I need to join Table A and Table B based on the fact that i have to look thru Table B and find the first records which have Value_a and Value_b.
i.e.: Loop thru the Table B and find the instance which has atleast 1 record in instance sequence(1,2,3,4)
So, first for 66 there are no records, we move on to 5 which also does not have any records in Table B, so we move on to 77 and find a record in Table B. We have to report that and display results:
Instance Value_a Value_b
77 10001 10002
|
|
|
|
|
|
|
|
|
Re: Instance Sequence Priority Values [message #610100 is a reply to message #610096] |
Mon, 17 March 2014 10:49 |
|
developer12
Messages: 88 Registered: July 2013
|
Member |
|
|
Here is how the DDL, DML and the results I need:
CREATE TABLE Table_a
(
SEQ NUMBER,
INSTANCE NUMBER
)
/
SET DEFINE OFF;
Insert into Table_a
(SEQ, INSTANCE)
Values
(1, 4);
Insert into Table_a
(SEQ, INSTANCE)
Values
(2, 274);
Insert into Table_a
(SEQ, INSTANCE)
Values
(3, 18);
Insert into Table_a
(SEQ, INSTANCE)
Values
(4, 26);
Insert into Table_a
(SEQ, INSTANCE)
Values
(5, 14);
COMMIT;
/
CREATE TABLE Table_b
(
E_DATE DATE,
ACC VARCHAR2(8) NOT NULL,
INSTANCE NUMBER NOT NULL,
TOTAL_VALUE NUMBER(38)
)
/
SET DEFINE OFF;
Insert into Table_b
(INSTANCE, E_DATE, ACC, TOTAL_VALUE)
Values
(14, TO_DATE('11/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'RR', 475.74);
Insert into Table_b
(INSTANCE, E_DATE, ACC, TOTAL_VALUE)
Values
(18, TO_DATE('11/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'RR', 479.99);
Insert into Table_b
(INSTANCE, E_DATE, ACC, TOTAL_VALUE)
Values
(26, TO_DATE('11/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'RR', 422.34);
COMMIT;
/
Results should display:
ACC E_DATE INSTANCE TOTAL_VALUE
RR 30-Nov-2011 18 479.99
The result is so because the total_value figure differs according to the instance in Table_b
|
|
|
Re: Instance Sequence Priority Values [message #610102 is a reply to message #610100] |
Mon, 17 March 2014 11:21 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> with
2 data as (
3 select a.seq, a.instance, b.e_date, b.acc, b.total_value
4 from table_a a, table_b b
5 where b.instance = a.instance
6 order by a.seq
7 )
8 select acc, e_date, instance, total_value
9 from data
10 where rownum = 1
11 /
ACC E_DATE INSTANCE TOTAL_VALUE
-------- ------------------- ---------- -----------
RR 30/11/2011 00:00:00 18 480
1 row selected.
|
|
|
Goto Forum:
Current Time: Fri Apr 26 13:46:34 CDT 2024
|