whi*_*ile 2 arrays google-bigquery
如果在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
Run Code Online (Sandbox Code Playgroud)
我想得到这样的东西:
+--------+--------+
| pair.x | pair.y |
+--------+--------+
| a | 1 |
| b | 2 |
| c | 3 |
+--------+--------+
Run Code Online (Sandbox Code Playgroud)
使用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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
523 次 |
| 最近记录: |