google-bigquery - BigQuery 数组 UNNEST 以返回数组中的不同值?

我有一个包含字符串数组字段的 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/

相关文章:

c# - 在 C# 中的 SQL CLR 函数中设置小数精度

azure - 属性错误: module 'pytest' has no attribute 'co

php - 试图从 laravel 中 Eloquent 产品评论中获取评论者的姓名

r - 使用 R Shiny 中的操作按钮将行从一个 DT 移动到其他 DT

ios - Flutter NSException : Configuration fails. 可

python - 合并具有两个公共(public)值的行 | Python

python - 当类的 __init__ 变量更改时如何检测和触发函数

pdf - 从 S3 读取 pdf 对象

r - 在 R 中将日期偏移一个月

javascript - 如何使用 react 模态显示没有背景效果的模态?