I am trying to unpivot multiple groups of columns with the same attribute but multiple value columns. Say there are 2 products and 3 customers.
I am trying to get a transformed table with 1 attribute(customer: customer1, customer2 and customer3) and 2 values (product1 and product2)
I tried spliting it into 2 tables and then unpivot each table and finally join both the tables. I believe this is an unreasonable approach.
I have also done using multiple selects with union all. The place where I am getting stuck is how will I fill the customer column as all the fields are numerical values and the customer column which is to be formed is categorical.
SELECT ID-1, ID-2, ID-3, product1_customer1 AS customer1, product1_customer2 AS customer2, product1_customer3 AS customer3
FROM table
UNION ALL
SELECT ID-1, ID-2, ID-3, product2_customer1, product2_customer2, product2_customer3
FROM table
How can I get the product column? Can you please point out in the direction where I'm going wrong?