select sum(t.amount) as total, a.id, t.id from accounts a, transactions t where a.id = t.id and rownum < ? group by (a.id, t.id)