I want to count all descendant of node
with recursive t as (
select a.id, 0 cntr from a
where parent_id = 12 union all
select a.id, cntr + 1 from t
join a on a.parent_id = t.id
where cntr <= 100
)
select * from t
But this example get depth count. I want to get all descendant different levels, and limit it. Result like this:
12, 0
13, 1
17, 2
...
232, 100
Table very big, select * and count it - not an option How can i do this?