BigQuery SQL: 无法查询重复字段的叉积 /
BigQuery SQL: Cannot query the cross product of repeated fields /
我的目标是从所有访问者中过滤,只分析客户(在 customDimension.index =2
中,然后进一步过滤特定类型的客户浏览量。
SELECT customDimensions.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`
WHERE customDimensions.index = 2
GROUP BY CustomerID
我得到的错误是(使用标准SQL):
Error: Cannot access field index on a value with type
ARRAY<STRUCT<index INT64, value STRING>> at [5:24]
旧版 SQL:
Error: Cannot query the cross product of repeated fields
customDimensions.index and hits.contentGroup.contentGroup2.
编辑:
SELECT cd.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`,
UNNEST(customDimensions) AS cd
WHERE cd.index = 2
GROUP BY CustomerID
returns:
Error: Cannot access field type on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [3:20]
我尝试使用 UNNEST(hits.type) = 'PAGE' AND UNNEST(hitscontentGroup.contentGroup2) = 'important'
更正 3:20 行,这给出了
Error: Syntax error: Unexpected keyword UNNEST at [3:15]
由于 customDimensions 是一个数组,您需要 unnest
这个数组才能引用它的内容,请参阅下面的 StandardSQL 示例,其中我从 BigQuery 中的 Google Analytics 数据中取消嵌套 UserID:
SELECT customDimension.value AS UserID
FROM `my.project.data` AS t
CROSS JOIN UNNEST(t.customdimensions) AS customDimension
WHERE customDimension.index = 2
我的目标是从所有访问者中过滤,只分析客户(在 customDimension.index =2
中,然后进一步过滤特定类型的客户浏览量。
SELECT customDimensions.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`
WHERE customDimensions.index = 2
GROUP BY CustomerID
我得到的错误是(使用标准SQL):
Error: Cannot access field index on a value with type
ARRAY<STRUCT<index INT64, value STRING>> at [5:24]
旧版 SQL:
Error: Cannot query the cross product of repeated fields customDimensions.index and hits.contentGroup.contentGroup2.
编辑:
SELECT cd.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`,
UNNEST(customDimensions) AS cd
WHERE cd.index = 2
GROUP BY CustomerID
returns:
Error: Cannot access field type on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [3:20]
我尝试使用 UNNEST(hits.type) = 'PAGE' AND UNNEST(hitscontentGroup.contentGroup2) = 'important'
更正 3:20 行,这给出了
Error: Syntax error: Unexpected keyword UNNEST at [3:15]
由于 customDimensions 是一个数组,您需要 unnest
这个数组才能引用它的内容,请参阅下面的 StandardSQL 示例,其中我从 BigQuery 中的 Google Analytics 数据中取消嵌套 UserID:
SELECT customDimension.value AS UserID
FROM `my.project.data` AS t
CROSS JOIN UNNEST(t.customdimensions) AS customDimension
WHERE customDimension.index = 2