select distinct a,b1 from ( select a,max(b) b1 from table group by a union all select a,min(b) b1 from table group by a having count(1)>1 )
select A,max(B) as B from table group by A union select A,max(B) from (select A,B from table minus (select A,max(B) as B from table group by A having Count(A)>2 )) group by A
select a,max(b) b1 from table group by a
union all
select a,min(b) b1 from table group by a having count(1)>1 )
union
select A,max(B) from
(select A,B from table
minus
(select A,max(B) as B from table group by A having Count(A)>2 ))
group by A