There's no need for a self join! It's just a matter of using analytics:
with emps as (
select 1 id, 1000 sal from dual union all
select 2 id, 2000 sal from dual union all
select 3 id, 3000 sal from dual union all
select 4 id, 4000 sal from dual union all
select 5 id, 5000 sal from dual
)
select id, sum(sal) over (order by id) from emps;
ID SUM(SAL)OVER(ORDERBYID)
1 1,000
2 3,000
3 6,000
4 10,000
5 15,000
In the over clause, pass the columns that determine which order to do the running total. For example, you could do it from highest to lowest like so:
with emps as (
select 1 id, 1000 sal from dual union all
select 2 id, 2000 sal from dual union all
select 3 id, 3000 sal from dual union all
select 4 id, 4000 sal from dual union all
select 5 id, 5000 sal from dual
)
select id, sum(sal) over (order by sal desc) from emps
order by id;
ID SUM(SAL)OVER(ORDERBYSALDESC)
1 15,000
2 14,000
3 12,000
4 9,000
5 5,000
For more details on how to do this, see Connor's video:
https://www.youtube.com/watch?v=1k-D3NPmlvg