I have the following table (it is really a view that is derived from complicate logic):
| TYPE | FIELD1 | FIELD2 | FIELD3 | FIELDNEEDSTOSTAYASCOLUMN |
|---------|--------|--------|--------|--------------------------|
| bad | 1 | 1 | 1 | 1000 |
| neutral | 2 | 2 | 2 | 1000 |
| good | 3 | 3 | 3 | 1000 |
I need to pivot it to the below. Take all the columns and move them as thr rows, but I need to keep the last column.
| FIELD | BAD | NEUTRAL| GOOD | FIELDNEEDSTOSTAYASCOLUMN |
|---------|--------|--------|--------|--------------------------|
| FIELD1 | 1 | 1 | 1 | 1000 |
| FIELD2 | 2 | 2 | 2 | 1000 |
| FIELD3 | 3 | 3 | 3 | 1000 |
I have tried using ORacl'es PIVOT and UNPIVOT but have been unable to create this.
This is a fiddle of the sql: