Im trying to translate column values to rows in PostgreSQL. Every player can play maximum of 3 matches per series (bof2). For every game he has pokemon he picked and points he scored. Here is how it looks:
| Player | Pokemon Picked | Picked | Match Series | Match id | Points |
|---|---|---|---|---|---|
| Ash | Charmander | 1 | 213 | 101 | 43 |
| Ash | Bulbasor | 2 | 213 | 102 | 52 |
| Ash | Pikachu | 3 | 213 | 103 | 70 |
| Brock | Onyx | 1 | 145 | 157 | 57 |
| Brock | Magmar | 2 | 145 | 158 | 63 |
| Gary | Charmander | 1 | 213 | 101 | 56 |
| Gary | Nidoking | 2 | 213 | 102 | 36 |
| Gary | Magmar | 3 | 213 | 103 | 34 |
Wanted Outcome:
| Player | First Match Pokemon | First Match Points | Second Match Pokemon | Second Match Points | Third Match Pokemon | Third Match Points |
|---|---|---|---|---|---|---|
| Ash | Charmander | 43 | Bulbasor | 52 | Pikachu | 70 |
| Brock | Onyx | 57 | Magmar | 63 | null | null |
| Gary | Charmander | 56 | Nidoking | 36 | Magmar | 34 |
I have tried using nth_element and ronumber() but cant figure it out with neither one.