Skip to content
Advertisement

SQL decode column value to another column

I am using PL/SQL 12.
I want to decode a column value to match another column value. I take the highest value of the the columns SP_RANK and MOODY_RANK and call it RANK. I want this column to instead of values have the corresponding value in either SP or MOODYS depending on which value is highest.

Below my code and a snippet of the data.

Table:

So instead of 100 it should say AAA and instead of 75 A, etc.

Advertisement

Answer

You can do this with a CASE statement:

You may need to add some extra logic to handle ties — i.e. which rank to use (SP or Moodys)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement