select max(A) from table_name; ---- takes the largest record in column A, say = 100;
select count(A) as countA from table_name where A=100;---- takes the number of records equal to the maximum value;
Then do the judgment
if countA =1
------implement the SQL as you specifically did
else
select max(B) from table_name;
fi