I'm looking for a query that will return me several rows into columns but without knowing the number of rows beforehand. I have searched and the only solutions I found involve knowing how many rows there are.
Here's an example table:
parentID colA colB
2 aaaaaa 1000.00
2 bbbbbb 1500.00
3 cccccc 500.00
3 dddddd 700.00
3 eeeeee 2000.00
and i need it to look like:
parentID colA(n) colB(n) colA(n+1) colB(n+1) colA(n+2) colB(n+2)
2 aaaaaaa 1000.00 bbbbbb 1500.00 NULL NULL
3 cccccc 500.00 dddddd 700.00 eeeeee 2000.00
I realize this should be done in PHP but I need it to be in mysql for a third party excel exporter plugin I'm using.
Edit: Is there a way to do this if I know the maximum number of columns I'll need?