Du kan "ranka" olika statusar baserat på din logik och sedan välja den senaste statusen ur dem. Du kan använda logiken som liknar den nedan, som trycker ner alla "avslag".
Se till att du inkluderar alla andra möjliga statusar om du bryr dig om beställningen för resten av dem.
with t1 as
( select 1 id, 'Waiver Requested' status from dual union all
select 1 id, 'Rejected' status from dual union all
select 2 id, 'Waiver Requested' status from dual union all
select 2 id, 'Waiver Requested' status from dual union all
select 3 id, 'Rejected' status from dual union all
select 3 id, 'Rejected' status from dual union all
select 4 id, 'Waiver Requested' status from dual union all
select 4 id, 'Cancelled' status from dual
)
select id,
status,
max(status) KEEP (DENSE_RANK FIRST
order by (case when status ='Rejected' then -1
else 1
end) desc)
over (partition by id) final_status
from t1
ID STATUS FINAL_STATUS
---------- ---------------- ----------------
1 Waiver Requested Waiver Requested
1 Rejected Waiver Requested
2 Waiver Requested Waiver Requested
2 Waiver Requested Waiver Requested
3 Rejected Rejected
3 Rejected Rejected
4 Waiver Requested Waiver Requested
4 Cancelled Waiver Requested