I want to query a table in this format:
ID| QTY | CODE
1 | 200 | C
1 | 500 | C
1 | 1000| C
1 | 2000| C
2 | 5000| A
2 | 3000| A
2 | 2500| A
2 | 2000| A
2 | 1000| B
2 | 500 | B
To create this:
ID | QTY1 | QTY2 | QTY3 | QTY4 | QTY5| CODE
1 | 200 | 500 | 1000 | 2000 | |C,C,C,C
2 | 500 | 1000 | 2000 | 2500 |3000 |B,B,A,A
The first 5 quantities are taken in ascending order and the codes are concatenated. Sometimes there are less than 5 quantities, in which case missing values are blank. If there are more than 5, the lowest 5 are taken.
Edit: version 5.6.41 The records in the source table are not in any order, the goal is to have the smallest quantity in QTY 1 inclreasing to QTY 5