I have a table in MySQL like this:
+-------+----------+
| am | ipiresia |
+-------+----------+
| 50470 | 29 |
| 50470 | 43 |
| 50433 | 29 |
| 6417 | 51 |
| 6417 | 52 |
| 6417 | 53 |
| 4960 | 25 |
| 4960 | 26 |
| 5567 | 89 |
| 6716 | 88 |
+-------+----------+
I want to transform it like this:
+-------+-----------+-----------+-----------+
| am | ipiresia1 | ipiresia2 | ipiresia3 |
+-------+-----------+-----------+-----------+
| 50470 | 29 | 43 | |
| 50433 | 29 | | |
| 6417 | 51 | 52 | 53 |
| 4960 | 25 | 26 | |
| 5567 | 89 | | |
| 6716 | 88 | | |
+-------+-----------+-----------+-----------+
Of course this is only a part of the table. The max occurrences of 'ipiresia' per 'am' can be up to 5, so I think a dynamic pivot table could do the work but I don't know how to do it.