SELECT
SUM(SAL) OVER (ORDER BY DATE) CUMSUM,
SUM(SAL) OVER (PARTITION BY ACCOUNT ORDER BY DATE) CUMSUM_OVER_ACCOUNT,
FROM
...
With a R - Data Table
ledgerExpenseCumulative <- ledgerExpense[,.(amount=sum(amount)),keyby=.(account,date)
][,.(date=.SD$date, amount=.SD$amount,cumAmount=cumsum(.SD$amount)),by=.(account)]
where: