Is it possible to create a repeated record column in BigQuery? For example, for the following data:
| a | b | c |
-------------
| 1 | 5 | 2 |
-------------
| 1 | 3 | 1 |
-------------
| 2 | 2 | 1 |
Is the following possible?
Select a, NEST(b, c) as d from *table* group by a
To produce the following results
| a | d.b | d.c |
-----------------
| 1 | 5 | 2 |
-----------------
| | 3 | 1 |
-----------------
| 2 | 2 | 1 |
With introduction of BigQuery Standard SQL we've got easy way to deal with records
Try below, Don't forget to uncheck Use Legacy SQL
checkbox under Show Options
WITH YourTable AS (
SELECT 1 AS a, 5 AS b, 2 AS c UNION ALL
SELECT 1 AS a, 3 AS b, 1 AS c UNION ALL
SELECT 2 AS a, 2 AS b, 1 AS c
)
SELECT a, ARRAY_AGG(STRUCT(b, c)) AS d
FROM YourTable
GROUP BY a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With