I want to count number of all child nodes under any level of tree structure maintained in a table using adjacency model (parent-child key). Table structure and data looks like this:
id - item- parentid
1 - A -
2 - B - 1
3 - C - 1
4 - D - 2
5 - E - 2
6 - F - 3
7 - G - 3
8 - H - 5
9 - I - 5
10 - J - 9
11 - K - 4
For example B has following child and grand child structure:
Now if you want to count "All child nodes of B" my answer should be 6.
Any pure SQL Query based solution would be of great help. Or mysql/php will also work.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…