It is necessary to calculate the cumulative sum in a table with a reordered row order (sorted by several fields). It turns out that you cannot use a query of the form:

Select sum(p.val) as sm from test p, test v where p.id<=v.id 

, since I cannot set the condition "where p.id <= v.id". How to be?

    1 answer 1

    Use explicit join

     Select v.id, sum(p.val) as sm from test p inner join test v on p.id<=v.id group by v.id