我是BigQuery的新手,请原谅我任何明显的错误。我正在尝试构建一个查询,我可以从一个自定义维度计算不同元素的数量,并将其与另一个自定义维度进行分组。
我尝试了这个,但它不起作用:
SELECT
MAX(IF(hits.customDimensions.index=7,hits.customDimensions.value,NULL)) AS Author,
COUNT(MAX(IF(hits.customDimensions.index=10,hits.customDimensions.value,NULL))) AS Articles
FROM (
SELECT
*
FROM
TABLE_DATE_RANGE([blablabla-blabla-115411:104672022.ga_sessions_test], TIMESTAMP('20160927'), TIMESTAMP('20161024'))) AS t0
GROUP BY
MAX(IF(hits.customDimensions.index=7,hits.customDimensions.value,NULL)) AS Author,
答案 0 :(得分:4)
使用standard SQL(取消选中“显示选项”下的“使用旧版SQL”),此查询是否有效?对于hits
中的每个条目,它选择作为作者的value
为7的index
,然后计算index
为10的条目数作为文章。它假设index
中最多有一个customDimensions
为7的条目。
SELECT
(SELECT value FROM UNNEST(hits.customDimensions)
WHERE index = 7) AS Author,
SUM((SELECT COUNT(*) FROM UNNEST(hits.customDimensions)
WHERE index = 10)) AS Articles
FROM
`your-dataset.ga_sessions_test` AS t, UNNEST(t.hits) AS hits
WHERE _PARTITIONTIME BETWEEN '2016-09-27' AND '2016-10-24'
GROUP BY Author;