Management Solutions Interview Question

How do you query this in SQL? how do you return this type in Java? etc...