having level and wanting to find parent ID
Hi,I got this table and data as follows,
CREATE TABLE test (seq NUMBER, nest NUMBER);
INSERT INTO test VALUES(1,1);
INSERT INTO test VALUES(2,2);
INSERT INTO test VALUES(3,3);
INSERT INTO test VALUES(4,3);
INSERT INTO test VALUES(5,1);
INSERT INTO test VALUES(6,2);
INSERT INTO test VALUES(7,2);
INSERT INTO test VALUES(8,3);
INSERT INTO test VALUES(9,3);
COMMIT;
SELECT * FROM test ORDER BY seq;
SEQ NEST
1 1
2 2
3 3
4 3
5 1
6 2
7 2
8 3
9 3
I would like to develop a query to produce the following result set.
SEQ NEST PARENT_SEQ
1 1 NULL
2 2 1
3 3 2
4 3 2
5 1 NULL
6 2 5
7 2 5
8 3 7
9 4 8
Any idea is appreciated.
Thanks,
Sha
CREATE TABLE test (seq NUMBER, nest NUMBER);
INSERT INTO test VALUES(1,1);
INSERT INTO test VALUES(2,2);
INSERT INTO test VALUES(3,3);
INSERT INTO test VALUES(4,3);
INSERT INTO test VALUES(5,1);
INSERT INTO test VALUES(6,2);
INSERT INTO test VALUES(7,2);
INSERT INTO test VALUES(8,3);
INSERT INTO test VALUES(9,3);
COMMIT;
SELECT * FROM test ORDER BY seq;
SEQ NEST
1 1
2 2
3 3
4 3
5 1
6 2
7 2
8 3
9 3
I would like to develop a query to produce the following result set.
SEQ NEST PARENT_SEQ
1 1 NULL
2 2 1
3 3 2
4 3 2
5 1 NULL
6 2 5
7 2 5
8 3 7
9 4 8
Any idea is appreciated.
Thanks,
Sha
0