0

I've got a table which looks like:

| id|cat|elems |
|---|---|------|
| 1 | A |[a, b]|
| 1 | B |[b, c]|
| 2 | C |[b, c]|

Where elems is an array column.

Is there a way I can pivot on the cat column without hardcoding the values of cat (so not doing a CASE/IF on cat='A', etc)? The desired result would look like:

| id| A    | B    |   C  |
|---|------|------|------|
| 1 |[a, b]|[b, c]| NULL |
| 2 | NULL | NULL |[b, c]|
krishonadish
  • 959
  • 2
  • 9
  • 18

1 Answers1

0

Google BigQuery doesn't have a PIVOT function. You can look how to simulate pivoting in the documentation here.

Also I would suggest you to take a look at those two Stack Overflow questions:

  1. How to Pivot in Google BigQuery
  2. Transpose rows into columns in BigQuery (Pivot implementation)
komarkovich
  • 2,223
  • 10
  • 20