在BigQuery中,可以使用ARRAY_AGG
和UNNEST
函数来对具有嵌套数据的行进行去重。以下是一个示例代码:
SELECT
column1,
ARRAY_AGG(DISTINCT nested_column) AS distinct_nested_column
FROM
dataset.table,
UNNEST(nested_array) AS nested_column
GROUP BY
column1
在上面的代码中,nested_array
是包含嵌套数据的数组列。首先,使用UNNEST
函数将嵌套数据展开为单独的行。然后,使用ARRAY_AGG(DISTINCT)
函数对展开的行进行去重,并将结果作为一个新的数组列distinct_nested_column
返回。最后,按照其他需要保留的列(例如column1
)进行分组。
请注意,这个示例假设数据集和表的名称为dataset.table
,需要根据实际情况进行替换。