I would like to create new columns based on values from another column dynamically.
For example ( fruits and quantity may be changed from time to time so the code should be able to create new columns as needed): I can do a case statement to create the two new columns : Banana, Apple.But how can I do it dynamically? - i.e tomorrow I'll get a new fruit like "Melon" or one fruit will be omitted.
ID FRUIT QUANTITY
22 Banana 5
33 Banana 1
44 Apple 3
Output
ID FRUIT QUANTITY Banana Apple
22 Banana 5 1 0
33 Banana 1 1 0
44 Apple 3 0 1
FRUITdata. Generally speaking, it's easier and more practical to perform pivoting in whatever tool you use to present (i.e. display) the data.