Hello,
I’m working on the tutorial at http://dev.mysql.com/tech-resources/articles/hierarchical-data.html.
This is the query:
SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM nested_category AS node,
nested_category AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.name
ORDER BY node.lft;
This is the result:
name depth
ELECTRONICS 0
TELEVISIONS 1
TUBE 2
LCD 2
PLASMA 2
PORTABLE ELECTRONICS 1
MP3 PLAYERS 2
FLASH 3
CD PLAYERS 2
2 WAY RADIOS 2
How would I modify the query to find out how many items are at each depth? Below is an example of what I would expect from the results:
Depth Number
0 1
1 2
2 6
3 1
Thanks in advance,
Tim