I have a table like this, with product name specified multiple times for each LAY it has:
NAME | LAYER | TYPE | DEPTH
-------------------------------------
32_42_1 | LAY_1 | A | 99.4
32_42_1 | LAY_2 | D | 427.2
32_42_1 | LAY_3 | X | 120.4
32_42_1 | LAY_4 | B | 27
32_42_2 | LAY_1 | A | 150.4
32_42_2 | LAY_2 | D | 427.2
32_42_2 | LAY_3 | X | 121.4
32_42_2 | LAY_4 | C | 40
32_42_3 | LAY_1 | F | 80.97
32_42_3 | LAY_2 | Y | 300.2
32_42_3 | LAY_3 | C | 123.4
32_42_3 | LAY_4 | C | 120
I need each NAME to only have one row and so it needs to be rotated like this:
NAME | LAY_1_TYPE | LAY_1_DEPTH | LAY_2_TYPE | LAY_2_DEPTH | LAY_3...
--------------------------------------------------------------------
32_42_1| A | 99.4 | D | 427.2 | ...
32_42_2| A | 150.4 | D | 427.2 | ...
32_42_3| F | 80.7 | Y | 300.2 | ...
I have found many similar solutions, and while some of them get close, I haven't been able to change the code to suit my needs.
This is what I have so far:
PIVOT
(
MAX(TYPE) For LAYER In (LAY_1,LAY_2,LAY_3,LAY_4,LAY_5)
) piv
But this only pivots one column, and doesn't condense the data into one row per "Name"
Any help would be appreciated!