add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t as
select 4 as job from dual union all
select 60 from dual union all
select 50 from dual union all
select 1 from dual union all
select 100 from dual union all
select 6 from dual
6 rows affected
with tt as (
select job, row_number() over (order by job desc) as seqnum
from t
),
cte(job, seqnum, processor, proc1, proc2, lev) as (
select job, seqnum, 1, job as proc1, 0 as proc2, 1
from tt
where seqnum = 1
union all
select tt.job, tt.seqnum,
(case when cte.proc1 > cte.proc2 then 2 else 1 end),
(case when cte.proc1 > cte.proc2 then cte.proc1 else cte.proc1 + tt.job end),
(case when cte.proc1 > cte.proc2 then cte.proc2 + tt.job else cte.proc2 end),
lev + 1
from cte join
tt
on tt.seqnum = cte.seqnum + 1
)
select *
from cte
order by seqnum
JOB SEQNUM PROCESSOR PROC1 PROC2 LEV
100 1 1 100 0 1
60 2 2 100 60 2
50 3 2 100 110 3
6 4 1 106 110 4
4 5 1 110 110 5
1 6 1 111 110 6