select * from table1 t1
where t1.D = (select max(t2.D)
from table1 t2
where t2.A in ('STERE', 'KG')
)
union all
select * from table1 t3
where where t2.A not in ('STERE', 'KG')
;
where t1.D = (select max(t2.D)
from table1 t2
where t2.A in ('STERE', 'KG')
)
union all
select * from table1 t3
where where t2.A not in ('STERE', 'KG')
;
from table1 t1
where t1.D =
(select max(t2.D) from table1 t2 where t2.A in ('STERE', 'KG'))
AND T1.A IN ('STERE', 'KG')
union all
select *
from table1 t3
where where t2.A not in ('STERE', 'KG');