【发布时间】:2019-10-04 18:41:56
【问题描述】:
我的表中有一个非重复记录列,我想访问它。 在这条记录上,有几个重复的值。
所以它是RECORD,就像这样:
STRUCT<item ARRAY<STRING> unit_cost ARRAY<INT64> quantity ARRAY<INT64>> as costs
例如。数据可能代表:
item ['cheese', 'ham', 'salad']
unit_cost [2, 5, 8]
quantity [1, 2, 1]
所以我想把它作为一个更好的数据结构,一个结构数组返回:
[
{'item': 'cheese', 'unit_cost': 2, 'quantity': 1},
{'item': 'ham', 'unit_cost': 5, 'quantity': 2}
{'item': 'salad', 'unit_cost': 8, 'quantity': 1}
]
我试过了:
SELECT ARRAY_AGG(costs)
但它会导致
[
{
"item": ['cheese', 'ham', 'salad'],
"unit_cost": [2, 5, 8],
"quantity": [1, 2, 1]
}
]
这不是我期望它返回的结果。
是否可以在这里巧妙地使用标准 SQL 从多个 ARRAY 中的 STRUCT 到多个 STRUCT 中的 ARRAY?
【问题讨论】:
标签: struct google-bigquery array-agg