mySQL aggregate query with hireachy
Nope.

The one query is a SELECT that fetches everything, then your application code does all the formatting work.

Or you make a messy Stored Procedure to do all that work.  And you spend longer than you would like debugging it.