You just need simple aggregation with having clause: DBFiddle
select
id,
max(payment_method)
keep(dense_rank last order by dt) as LAST_PAYMENT_METHOD
from t
group by id
having count(distinct payment_method)>1;
Full example with test data:
with t(ID, PAYMENT_METHOD, DT) as (
select 1, 'CASH' , to_date(2022,'YYYY') from dual union all
select 1, 'VISA' , to_date(2021,'YYYY') from dual union all
select 1, 'CASH' , to_date(2020,'YYYY') from dual union all
select 2, 'CASH' , to_date(2021,'YYYY') from dual union all
select 2, 'CASH' , to_date(2020,'YYYY') from dual union all
select 2, 'CASH' , to_date(2019,'YYYY') from dual union all
select 3, 'CHEQUE', to_date(2021,'YYYY') from dual union all
select 3, 'VISA' , to_date(2020,'YYYY') from dual union all
select 3, 'VISA' , to_date(2019,'YYYY') from dual union all
select 4, 'CASH' , to_date(2021,'YYYY') from dual union all
select 4, 'CASH' , to_date(2020,'YYYY') from dual union all
select 4, 'CASH' , to_date(2019,'YYYY') from dual
)
select
id,
max(payment_method)
keep(dense_rank last order by dt) as LAST_PAYMENT_METHOD
from t
group by id
having count(distinct payment_method)>1;
Output:
ID LAST_PAYMENT_METHOD
---------- --------------------
1 CASH
3 CHEQUE