I am using MySQL and let's say I have a table below
Department | Sale Month | Sale Amount |
----------- | ---------- | ----------- |
Sports | January | 500.00 |
Sports | March | 200.00 |
Leisure | February | 1000.00 |
Consumables | January | 250.00 |
Consumables | February | 100.00 |
Consumables | March | 40.00 |
Clothing | February | 50.00 |
Clothing | March | 300.00 |
I need to compress the above table into a new table that groups each Department
. I also need to add three new columns for each Sale Month
and their respective Sale Amount
Basically, the final result should like something like this
Department | January | February | March |
----------- | ---------- | ----------- | -------- |
Sports | 500.00 | - | 200.00 |
Leisure | - | 1000.00 | - |
Consumables | 250.00 | 100.00 | 40.00 |
Clothing | - | 50.00 | 300.00 |
What is the necessary function or way to transform the table like this?
Thanks!