1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| with MaTable as
(
select 80 as dpt, 'S1' as pos from dual union all
select 80 , 'S1' from dual union all
select 80 , 'S2' from dual union all
select 80 , 'S4' from dual union all
select 80 , 'S3' from dual union all
select 80 , 'S3' from dual union all
select 60 , 'S3' from dual union all
select 60 , 'S4' from dual
)
select dpt as departement_id,
max(case pos when 'S2' then 'Y' else 'N' end) as position_y_or_n
from MaTable
group by dpt
order by dpt desc;
DEPARTEMENT_ID POSITION_Y_OR_N
-------------- ---------------
80 Y
60 N |