【发布时间】:2018-04-16 09:51:39
【问题描述】:
我的目标是过滤所有访问者,仅分析客户(位于 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
我收到以下错误(使用 StandardSQL):
Error: Cannot access field index on a value with type
ARRAY<STRUCT<index INT64, value STRING>> at [5:24]
对于旧版 SQL:
错误:无法查询重复字段的叉积 customDimensions.index 和 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
返回:
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]
【问题讨论】:
-
我猜你正在寻找unnest。
FROM xxxxxxxx.ga_sessions_20180415, unnset(customDimensions) as cd where cd.index = 2(您也可以在子查询中取消嵌套以保留行数) -
@danihp 我仍然得到相同的错误(标准 SQL) - 错误:无法访问类型为 ARRAY
> at [1:25] 的值的字段值 -
@GRS 。 . .你有一个数组。您需要从数组中提取一个或多个元素以进行查询。如果我们能看到数据的样子会有所帮助。
标签: sql google-bigquery legacy-sql