I am trying to find the parent with the most children. I feel like this should not be so hard however I find myself struggling.
I am using postgresql and Ltree.
Thank you
I am trying to find the parent with the most children. I feel like this should not be so hard however I find myself struggling.
I am using postgresql and Ltree.
Thank you
It's the same logic as for any other case, find a function that will give you the parent and group by it. This should work:
SELECT subpath(path,0,1), count(*)
FROM test
GROUP BY subpath(path,0,1)
ORDER BY count(*) DESC limit 1;