【发布时间】:2016-07-06 22:33:59
【问题描述】:
我正在尝试使用新的标准 SQL 在 Google BigQuery 表中的结构数组中查找具有重复字段的行。表中的数据(简化),其中每一行看起来有点像这样:
{
"Session": "abc123",
"Information" [
{
"Identifier": "e8d971a4-ef33-4ea1-8627-f1213e4c67dc"
},
{
"Identifier": "1c62813f-7ec4-4968-b18b-d1eb8f4d9d26"
},
{
"Identifier": "e8d971a4-ef33-4ea1-8627-f1213e4c67dc"
}
]
}
我的最终目标是显示具有 Information 实体且存在重复 Identifier 值的行。但是,我尝试的大多数查询都会收到以下形式的错误消息:
Cannot access field Identifier on a value with type ARRAY<STRUCT<Identifier STRING>>
有没有办法在ARRAY 内处理STRUCT 内的数据?
这是我第一次尝试查询:
SELECT
Session,
Information
FROM
`events.myevents`
WHERE
COUNT(DISTINCT Information.Identifier) != ARRAY_LENGTH(Information.Identifier)
LIMIT
1000
另一个使用子查询:
SELECT
Session,
Information
FROM (
SELECT
Session,
Information,
COUNT(DISTINCT Information.Identifier) AS info_count_distinct,
ARRAY_LENGTH(Information) AS info_count
FROM
`events.myevents`
WHERE
COUNT(DISTINCT Information.Identifier) != ARRAY_LENGTH(Information.Identifier)
LIMIT
1000)
WHERE
info_count != info_count_distinct
【问题讨论】:
-
提出您的查询(即使它是错误的),这样我们就可以开始一些事情了!
-
没问题!编辑问题以添加我所做的两次尝试。
-
您有机会检查/尝试我的答案吗?
标签: sql google-bigquery