HangOver
HangOver

Reputation: 3

oracle query - something similar to pivot, but

I have a table like this:

ID_ORIG    ID_DEST       DISTANCE  
-------    -------      --------  
1          101          10              
1          102          15  
1          103          20  
2          101          25  
2          102          30  
2          103          35  
3          101          40  
3          102          45  
3          103          50  

And I want the following result:

ID_ORIG     101         102         103
-------     ---         ---         ---
1           10          15          20
2           25          30          35
3           40          45          50

I tried to use 'pivot', but obiously didn't achive this result. Database is Oracle 11g.
Any help would be appreciated.

Upvotes: 0

Views: 76

Answers (1)

TechDo
TechDo

Reputation: 18639

Please try:

select * From(
    select * from YourTable
  ) PIVOT (sum(DISTANCE) for (ID_DEST) IN (101, 102, 103));

SQL Fiddle Demo

Upvotes: 2

Related Questions