My goal is to have a table with the following structure:
| Company name | December 2021 | November 2021 | October 2021 | ... | January 2021 |
|---|---|---|---|---|---|
| 70 | 30 | 20 | ... | 80 | |
| Amazon | 30 | 45 | 34 | ... | 24 |
| ... |
It contains for each company the credit of all the clients within that particular month.
I want to keep track only of the last 12 months (the table gets updated monthly). In January 2022 I would want the column order to change as follows:
| Company name | January 2022 | December 2021 | November 2021 | ... | February 2021 |
|---|---|---|---|---|---|
| 25 | 70 | 30 | ... | 14 | |
| Amazon | 80 | 30 | 45 | ... | 33 |
| ... |
In February 2022 it would change in:
| Company name | February 2022 | January 2022 | December 2021 | ... | January 2021 |
|---|---|---|---|---|---|
| 37 | 25 | 70 | ... | 20 | |
| Amazon | 42 | 80 | 30 | ... | 21 |
| ... |
Assuming that I can retrieve the credit values from a table with the following structure:
| Company name | Month | Value |
|---|---|---|
| December 2021 | 70 | |
| Amazon | December 2021 | 30 |
| November 2021 | 30 | |
| Amazon | November 2021 | 45 |
| ... |
do you know how to do that in SQL?