sql - Need a query to insert 'level' into an adjacent list -
i have table so
id node parentid 1 0 2 b 1 3 c 1 4 d 2 5 e 2 6 f 3 7 g 3 8 h 3 9 4 10 j 4 11 k 10 12 l 11
i need query generate 'level' field shows how many levels deep particular node is. example below
id node parentid level 1 0 1 2 b 1 2 3 c 1 2 4 d 2 3 5 e 2 3 6 f 3 4 7 g 3 4 8 h 3 4 9 4 5 10 j 4 5 11 k 10 6 12 l 11 7
select id, node, parentid, dense_rank() over(order parentid) level table_name
Comments
Post a Comment