I have a customers table as following:
customername, ordername, amount
=============================
bob, book,     20
bob, computer, 40
steve,hat,     15
bill, book,    12
bill, computer, 3
steve, pencil, 10
bill, pen,      2
I want to run a query to get the following result:
customername, ordername, amount
=============================
bob,   computer, 40
bob,   book,     20
bob,   ~total~,  60
steve, hat,      15
steve, pencil, 10
steve, ~total~,25 
bill, book,    12
bill, computer, 3
bill, pen,      2 
bill, ~total~, 17
I want the amount for each customer to be ordered from max to min and a new ordername as "~total~" (must always be the last row for each customer) with a result as sum of all amount for the same customer. So, in above example, bob should be the first since the total=60, steve the second (total=25) and bill the third (total=17).