U kunt verschillende statussen "rangschikken" op basis van uw logica en er vervolgens de laatste status uit kiezen. U kunt de logica gebruiken die vergelijkbaar is met die hieronder, die alle "afwijzingen" naar beneden duwt.
Zorg ervoor dat u alle andere mogelijke statussen opneemt als u de rest van de bestelling belangrijk vindt.
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