Acho que esta consulta funcionará: selecione id,type,amount,(select sum(amount) from mytable t1 onde t1.type=t2.type and t1.id<=t2.id) currenttotal from mytable t2