COUNTING results from self-referenced table recursively
As your data is a tree structure, consider using the Nested Set data model.

A good write-up can be found at Mike Hillyer's website, here:  http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

complete with lots of SQL to manage the tree data.