0

I have this table in MySQL Database.

YYYYMM  Value   Counts

201701  InSTOCK   10
201702  InSTOCK   5
201703  InSTOCK   2
201704  InSTOCK   4
201702  newstock  4
201703  newstock  8
201704  newstock  8
201701  reserve   3
201702  reserve   3
...
202201

I would like to transpose my Data like this:

 YYYYMM   InSTOCK   newstock  reserve
 201701    10                   3
 201702    5          4         3
 201703    2          8
 201704    4          8
 ...
 202201

Note that each new month a row is gonna be added in YYYYMM. How I can perform this transformation?

Simon GIS
  • 1,045
  • 2
  • 18
  • 37
  • 1
    You may try the suggested solution here https://stackoverflow.com/questions/12004603/mysql-pivot-row-into-dynamic-number-of-columns . But if it's different than your situation then tell us what have you tried? Also, please run `SELECT version();` to check MySQL specific version. – FanoFN Jan 28 '22 at 03:15
  • 1
    Does the list `'InSTOCK', 'newstock', 'reserve'` is complete and won't be expanded in future? – Akina Jan 28 '22 at 04:39

0 Answers0