I have products in categories and my categories are of multiple levels. I want to calculate number of products at parent category level. some of the categories have 3 levels and some have 4, its not fixed, but at least 2 levels are required. Means parent and child is required but in some cases there may be child of child and so on to up n level.

I want to calculate number of products in all the children categories of a parent category, is it possible? if its it is please help me out.

Tables Structure is like this:
Product Table: productId,title,catid
Category Table:catid,catname,parentcat