Grouping and summing at multiple levels often takes an application to perform. Take a look at the ROLLUP operation within Oracle and perform these operations in a single SQL statement.

This story continues at
http://www.dbasupport.com/oracle/ora10g/JustSQL08.shtml