如果我在BigQuery中有两个数组,我知道它们的大小相同。我如何将它们压缩成一个结构数组或两个元素数组或类似的数组?
以下查询给出了x和y的所有可能组合,这不是我想要的。
WITH test AS (
SELECT
['a', 'b', 'c'] as xs,
[1, 2, 3] as ys
)
SELECT struct(x, y) as pairs
FROM test, unnest(xs) as x, unnest(ys) as y
我想得到这样的东西:
+--------+--------+
| pair.x | pair.y |
+--------+--------+
| a | 1 |
| b | 2 |
| c | 3 |
+--------+--------+
答案 0 :(得分:3)
使用WITH OFFSET
和括号运算符:
WITH test AS (
SELECT
['a', 'b', 'c'] as xs,
[1, 2, 3] as ys
)
SELECT struct(x, ys[OFFSET(off)] as y) as pairs
FROM test, unnest(xs) as x WITH OFFSET off;