Hello again. There is a table:
create table test_table ( id integer not null, name char(1) not null, parent_id integer, sum integer not null); INSERT INTO test_table VALUES(1, 'A', null, 300); INSERT INTO test_table VALUES(11, 'B', 1, 2340); INSERT INTO test_table VALUES(111, 'C', 11, 3200); INSERT INTO test_table VALUES(22, 'D', 1, 7540); INSERT INTO test_table VALUES(2, 'E', null, 6300); INSERT INTO test_table VALUES(3, 'F', 2, 8600); INSERT INTO test_table VALUES(101, 'G', 3, 3800); INSERT INTO test_table VALUES(102, 'H', 3, 9700); And there is a code:
SELECT lpad(' ', 3*level)||name as Tree FROM test_table A START WITH parent_id is null CONNECT BY PRIOR id = parent_id; How to do the same without using CONNECT BY (through WITH )?
So, I found an application using WITH ( here ), but it just doesn't work - it shows the name of the CTE and says that the key word is missing:
WITH RECURSIVE Rec (id, parent_id, name) AS ( SELECT id, parent_id, name FROM test_table UNION ALL SELECT Rec.id, Rec.parent_id, Rec.name FROM Rec, test_table WHERE Rec.id = test_table.parent_id ) SELECT * FROM Rec WHERE parent_id is null;