My first question here. I did try to search a similar question and answer but somehow did not return exactly what I was after.
I have an original table like the following. The Forecast volumes are stacked up by the period.
I was trying to "Unstack" the table to have a main column for products and the forecast volumes in each different column for different period.
Original table:
Product | Period | Forecast Volume |
---|---|---|
Product1 | Jan-21 | 500 |
Product2 | Jan-21 | 200 |
Product3 | Jan-21 | 300 |
Product1 | Feb-21 | 400 |
Product3 | Feb-21 | 500 |
Product1 | Mar-21 | 120 |
Product2 | Mar-21 | 50 |
Product3 | Mar-21 | 180 |
Product4 | Mar-21 | 200 |
Desire table:
Product | Jan-21 | Feb-21 | Mar-21 |
---|---|---|---|
Product1 | 500 | 400 | 120 |
Product2 | 200 | 50 | |
Product3 | 300 | 500 | 180 |
Product4 | 200 |
I have attempted to first, create a table with a column of all the unique product names. Then keep joining the table for the volumes of each month. I was able to do for two months But it's not scalable if there are many periods.
I use MySQL but solutions of any application will help. I can manage to convert the syntax. Thanks.