Pivoting a table using Unique/Distinct Values
I have got data that looks like this table(I have simplified the table, but the idea is to get the number of unique product ids form unique columns and insert discount id where customer id meets product id, otherwise it will be a missing value(?)):
CustomerID | Product | Discount ID |
---|---|---|
Customer1 | Product1 | D1 |
Customer1 | Product2 | D3 |
Customer2 | Product1 | D2 |
Customer3 | Product3 | D3 |
I would like to turn this into this form:
CustomerID | Product1 | Product2 | Product3 |
---|---|---|---|
Customer1 | D1 | ? | ? |
Customer1 | ? | D3 | ? |
Customer2 | D2 | ? | ? |
Customer3 | ? | ? | D3 |
I have played around with the PIVOT operator but I am struggling to achieve this.
Thanks very much in advance!