我遇到了一个案例,我可以在GA中看到CustomDimension1对特定ID(CustomDimension 2)的值。但是当我使用标准SQL从BigQuery中提取值时,我找不到该值,而是显示空值。
SELECT fullVisitorId, CD1, CD2
FROM (
SELECT
fullvisitorid,
(SELECT MAX(IF(index=1, value, NULL)) FROM UNNEST(hits.customDimensions)) AS CD1,
(SELECT MAX(IF(index=2, value, NULL)) FROM UNNEST(hits.customDimensions)) AS CD2
FROM `XXXXXXXXXXXXX`, UNNEST(hits) AS hits
)
WHERE CD2= '111111' and CD1 IS NOT NULL
答案 0 :(得分:1)
您不需要标准sql中的MAX(IF(...))
技巧,只需在SELECT
语句中使用子选项 - 例如(SELECT value FROM UNNEST(customDimensions) WHERE index=1) AS cd1
或特定情况
SELECT
fullvisitorid, visitstarttime, hitnumber,
(SELECT cd.value
FROM h.customDimensions AS cd
WHERE cd.index=16 ) AS hitsCd2
FROM
`project.dataset.ga_sessions_20171210` AS t, t.hits as h -- flatten to hits scope with cross join
LIMIT
1000
一般方法是:首先展平到您想要的尺寸范围,在这种情况下命中范围。然后计算所有指标 - 较低范围的子选择和更高范围的计数(不同some_id)。