This is mainly for my information so I can find it when I need it next time.

You have to have a query that groups over something, preferably doing a SUM() (haven't tried it with anything else) and put WITH ROLLUP at the end. Do something like:

SELECT name, purchaseid, sum(amount) from purchases group by name, purchaseid WITH ROLLUP

You will get results like:

A    1    10
A 2 10
A NULL 20 <-- subtotal
B 1 15
B NULL 15 <-- subtotal
NULL NULL 35 <-- grand total

</p>