Thread:Semantic-mediawiki.org:Community portal/How do I build a query that counts pages by category or subcategory?

Consider this simple situation:

I have a category called Parent Category with two sub categories called First Child and Second Child.

I have a Page A and a Page B that have the category First Child. I have a Page C has the category Second Child.

What I want to do is count the number of pages in each category. I can get a count of pages under the Parent Category: { { #ask: [ [Category: Parent Category] ] | format = count} }

I can produce a table of pages by category: { { #ask: [ [Category: Parent Category] ] | format = table} }

But, how do I do both so that I have a table that looks like this:

I've tried a few things without success. Here is one example: { { #ask: [ [Category: Parent Category] ] | ?Category | ?count | format = table } }

Any advice you have would be appreciated.