0 sql google-analytics google-bigquery
我在查询时遇到问题hits.product.customDimensions(相同的逻辑在 上正确工作hits.customDimensions)。我不明白为什么额外的嵌套会导致数组错误。任何帮助表示赞赏。谢谢你!
标准SQL
SELECT
fullVisitorId,
visitId,
hits.hitNumber,
product.productSKU,
MAX(IF(c.index=1,c.value, null)) AS customDimesion1
FROM 17823880.ga_sessions_20180128,
UNNEST(hits) AS hits,
UNNEST(hits.product) as product,
UNNEST(hits.product.customDimensions) as c
GROUP BY 1, 2, 3, 4
Run Code Online (Sandbox Code Playgroud)
错误:
无法在 [11:23] 访问类型为 ARRAY> 的值上的字段 customDimensions
标准 SQL - 此查询运行时不会出现以下错误
SELECT
fullVisitorId,
visitId,
hits.hitNumber,
MAX(IF(c.index=1,c.value, null)) AS customDimesion1
FROM 17823880.ga_sessions_20180128,
UNNEST(hits) AS hits,
UNNEST(hits.customDimensions) as c
GROUP BY 1, 2, 3
Run Code Online (Sandbox Code Playgroud)
product问题是您为来自 的元素提供了别名UNNEST(hits.product),但您没有在后续的 中引用该别名UNNEST(hits.product.customDimensions),因此在取消嵌套后您最终得到的是原始product数组而不是其元素。试试这个:
SELECT
fullVisitorId,
visitId,
hits.hitNumber,
product.productSKU,
MAX(IF(c.index=1,c.value, null)) AS customDimesion1
FROM 17823880.ga_sessions_20180128,
UNNEST(hits) AS hits,
UNNEST(hits.product) as product,
UNNEST(product.customDimensions) as c
GROUP BY 1, 2, 3, 4
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2680 次 |
| 最近记录: |