Re: Count Hierarchical Data(Binary Tree) in MySQL?
A leaf is a node that has no child nodes. Your 14 &c example counts are child node counts, not leaf node counts. To retrieve those counts, try something like ...
SELECT parent.id, Count(distinct child.id) - 1 AS 'Child Nodes'
FROM tbl parent
JOIN tbl child ON child.left_id BETWEEN parent.left_id AND parent right_id
GROUP BY parent.id;
PB
http://www.artfulsoftware.com
Subject
Views
Written By
Posted
4381
January 27, 2010 04:38AM
Re: Count Hierarchical Data(Binary Tree) in MySQL?
2755
January 27, 2010 10:19AM
2374
January 29, 2010 02:56AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.