0

I am working on a project where I have to solve the following problem.

Goal:

  1. If there are two rows that same the same identifier, but additional data that is different, how can I combine all of that data into one row with individual columns?

Example:

DateBase:

| ID   | Rating | Rating Provider|
--------------------------------
| 5055 | A+     | Moodys         | 
---------------------------------
| 5055 | Bb+    | SNP            |

Desired End Result:

| ID   | Moodys | SNP | 
--------------------
| 5005 | A+     | Bb+ | 
JNevill
  • 46,980
  • 4
  • 38
  • 63
  • Does this answer your question? [Oracle SQL pivot query](https://stackoverflow.com/questions/4841718/oracle-sql-pivot-query) – astentx Aug 03 '22 at 16:48

2 Answers2

2

I believe you simply need a Pivot -

SELECT *
  FROM YOUR_TABLE
 PIVOT(MAX(Rating)
       FOR Rating_Provider IN (Moodys AS 'Moodys', SNP AS 'SNP'));
Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40
0

Quantnesto, i believe that what you are looking for it's the JOIN function. You have the information in different databases, right?

  1. You SELECT all the fields that you want from the different tables
SELECT a.ID,a.Moodys,B.SNP
FROM DataBase a
JOIN Database b on a.ID = b.ID

And that's it.

There are different kinds of JOIN's, for further information let me know, i can explain each type.

Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40