I have the following SQL query running against an Oracle 11g instance that works great:
SELECT
TRIM(PART_NM) || TRIM(PART_NO),
TRIM(MKBY_IND),
MFG_TYP
FROM
TblPARTS
WHERE
ORDER_START_DATE >= (SYSDATE - 365)
AND
TO_CHAR(TRIM(PART_NO)) != '99'
Which yields results like the following:
| Part | Make / Buy | Area |
|:----:|:----------:|:---------:|
| AU54 | M | Demo |
| ZA45 | M | Construct |
| AD28 | B | Construct |
| SX73 | B | Construct |
| MO47 | M | Construct |
| IN66 | B | Construct |
| RP42 | M | Demo |
| HF77 | B | Demo |
| IE43 | B | Personal |
| OX11 | B | Personal |
| ZE45 | M | Demo |
| JH21 | M | Construct |
| AM91 | M | Construct |
| DS50 | M | Demo |
| LE29 | M | Demo |
| IP91 | M | Demo |
| ID42 | M | Demo |
| RI96 | M | Demo |
I have no problems there. However, it has been requested for me to transpose the Area column and instead group the rows by it. Something akin to:
| Part | Make / Buy |
|:---------:|:----------:|
| CONSTRUCT | CONSTRUCT |
| AU54 | M |
| ZA45 | M |
| AD28 | B |
| SX73 | M |
| MO47 | M |
| IN66 | B |
| JH21 | M |
| AM91 | B |
| DEMO | DEMO |
| RP42 | M |
| HF77 | M |
| ZE45 | M |
| DS50 | B |
| LE29 | M |
| IP91 | M |
| ID42 | M |
| RI96 | M |
| PERSONAL | PERSONAL |
| IE43 | M |
| OX11 | M |
In short, I am looking to find the unique values in the "Area" column (MFG_TYP
) field, and to be able to group by them in a row. It should be noted that the three entries listed are valid in my dataset, but are subject to change, so I am not looking for a static solution, but instead a way to dynamically apply the transformation across all unique values in the Area
column.
I have tried looking at these resource's but currently do not understand how to build a solution. Any advice is appreciated.