我的表上有一个不重复的记录列,我想访问它。在这个记录上,有几个重复的值。
所以它是一个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从STRUCT
多个ARRAY
变为ARRAY
多个?STRUCT