我在查询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
错误:
无法对具有类型的值访问字段customDimensions ARRAY>在[11:23]
标准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
答案 0 :(得分:2)
问题是您为来自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