我有一个包含字符串数组字段的 BigQuery 表。对于某些记录,该数组可以包含重复的字符串值。
是否可以在 BigQuery UNNEST 子句中过滤掉重复项,以便 UNNEST 仅返回不同的数组字符串值?
最佳答案
有很多方法可以做到这一点。由于您没有指定所需的输入和输出,我将任意选择一个。
使用 ARRAY_AGG(DISTINCT)
:
WITH data AS (
SELECT 1 id, ["a", "a", "b", "e", "a", "c", "b", "a"] strings
)
SELECT id, ARRAY_AGG(DISTINCT string) strings
FROM data, UNNEST(strings) string
GROUP BY id
https://stackoverflow.com/questions/62759481/