Given the following SQL
SELECT
T1."PN" as "Part Number",
T2."QTY" as "Quantity",
T2."BRANCH" AS "Location", T3."STOCK" as "Bin"
FROM
"XYZ"."PARTS" T1,
"XYZ"."BALANCES" T2,
"XYZ"."DETAILS" T3
WHERE (T2."PART_ID" = T1."PART_ID") AND (T3."PART_ID" = T1."PART_ID")
ORDER BY "Part Number" ASC, "Location" ASC
We get results such as
YZ-7-CA-080 88 01 STOCK7
YZ-7-CA-080 88 01 03482
YZ-7-CA-080 88 01 A8K2D
For location 01, there are 88 pieces of that part number YZ-7-CA-080 and they can be found in any of the 3 bins STOCK7, 03482, or A8K2D. The location value refers to a common branch like a warehouse and the quantity is for the entire warehouse, not the bins.
I need to change the output so we can write out instead one entry with bins as a list
YZ-7-CA-080 88 01 STOCK7,03482,A8K2D
So I am looking for a good way to do this refactoring of the results in SQL. I feel there should be a way to use a function or subquery or something like that and hoping there is a single multi-db solution but assume there could be a need for different solutions on different dbs. (Oracle is the primary solution we are trying to solve but secondary priority db we need this for is SQL Server).
Note: There are multiple locations per part number so its not enough to set distinct on the first column to reduce the multiple part number entries. There would be multiple of the same part number at location 02 also with the same issue.
Ideas?