Current location - Loan Platform Complete Network - Big data management - oracle how to take the largest record in column A in a table, if column A is equal to the maximum value and there are more than one at the same time, take the largest record in column B.
oracle how to take the largest record in column A in a table, if column A is equal to the maximum value and there are more than one at the same time, take the largest record in column B.
This is not something that can be done with a simple SQL, you need to use a cursor, or a stored procedure.

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