MySQL Forums
Forum List  »  Knowledge Base

Count Hierarchical Data(Binary Tree) in MySQL?
Posted by: Manivel P
Date: January 27, 2010 04:38AM

Hi,

I have questing on counting leaf nodes of binary tree.

My tables looks like below.

+------+---------+----------+
| ID | LEFT_ID | RIGHT_ID |
+------+---------+----------+
| 1 | 2 | 3 |
| 2 | 4 | 5 |
| 3 | 6 | 7 |
| 4 | 8 | 9 |
| 5 | NULL | NULL |
| 6 | 10 | 11 |
| 7 | 12 | 13 |
| 10 | 14 | 15 |
| 11 | NULL | NULL |
| 12 | NULL | NULL |
| 13 | NULL | NULL |
| 14 | NULL | NULL |
| 15 | NULL | NULL |
| 8 | NULL | NULL |
| 9 | NULL | NULL |
+------+---------+----------+

using this data i want count total leaf's.

For example count of leaf is 14 for 1, 4 for 2, 8 for 3, etc..

If anybody have thoughts to get this count in mysql db.

thanks,
-Mani

Options: ReplyQuote


Subject
Views
Written By
Posted
Count Hierarchical Data(Binary Tree) in MySQL?
4353
January 27, 2010 04:38AM


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.