0

I have a data set in which I'm basically trying to combine values from multiple rows that represent a category for unique ID, but I'm not sure how to do this. Hopefully my example data will show what I'm struggling with best:

id category value customerid 
1 Orange 23423 1
2 Banana 5675 1 
3 Apple 34534 1 
4 Donut 94534 2
5 Pineapple 750365 1

So essentially, a customer may have multiple items that are of a category, I'd like to select this data in a way that looks like this:

customerid Orange_value Banana_value Apple_value Donut_value Pineapple_value
1 23423 5675 34534 null 750365 
2 null null null 94534 null 

The columns don't necessarily need to have '_value' appended to the column name, but this code does have to look at the distinct results in the previous table, as these could change at any point. Could anyone give me some advice on how to do this please?

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
nootskej
  • 69
  • 7

0 Answers0