Income statement table has structure:
sgroup char(30),
account char(10),
jan numeric(12,2),
feb numeric(12,2)
and has values:
SGroup Account Jan Feb
Sales 311 100 200
Sales 312 20 30
..
Other 410 3333 44
Other 411 333 344
...
How convert this table to have header and subtotals for each group:
Caption Jan Feb
Sales
311 100 200
312 20 30
Sales Total 120 230
Other
410 3333 44
411 333 344
Other total 3666 388
... ... ...
Grand Total ... ...
Caption column should contain group header, account numbers and group total for each group. After total there should be empty row. After that that there should be next group etc. In the end there should be a "Grand Total" row containing the sum of all rows.
Using Postgres 9.1.2 in Debian.
Mono C# ASP.NET MVC application running in Debian. If it's more reasonable, this conversion can done in MVC controller also.