Google bigquery 使用where语句和展平自定义维度
我构建了以下查询:Google bigquery 使用where语句和展平自定义维度,google-bigquery,Google Bigquery,我构建了以下查询: SELECT MAX(IF (hits.customDimensions.index = 10, hits.customDimensions.value, NULL)) WITHIN RECORD AS postId, DATE(MAX(IF (hits.customDimensions.index = 4, hits.customDimensions.value, NULL))) WITHIN RECORD AS Datepublished, MAX(IF (h
SELECT
MAX(IF (hits.customDimensions.index = 10, hits.customDimensions.value, NULL)) WITHIN RECORD AS postId,
DATE(MAX(IF (hits.customDimensions.index = 4, hits.customDimensions.value, NULL))) WITHIN RECORD AS Datepublished,
MAX(IF (hits.customDimensions.index = 1, hits.customDimensions.value, NULL)) WITHIN RECORD AS Country,
MAX(IF (hits.customDimensions.index = 7, hits.customDimensions.value, NULL)) WITHIN RECORD AS Author,
FROM
(TABLE_DATE_RANGE([storied-toolbox-145015:102152044.ga_sessions_], DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY')))
但是,我希望能够使用基于自定义维度之一的where语句。类似这样的where Country='fr'
。我尝试过各种解决方案,但我总是遇到Over子句错误或scope错误
因为我想在GoogleDataStudio中使用这个查询,所以我需要使用SQL legacy来构建它
谢谢
。。。我希望能够基于一个自定义维度使用where语句
下面假设您的查询按照您的预期工作,因此它只解决按国家“筛选”的问题,这基本上就是问题所在
SELECT
MAX(IF (hits.customDimensions.index = 10, hits.customDimensions.value, NULL)) WITHIN RECORD AS postId,
DATE(MAX(IF (hits.customDimensions.index = 4, hits.customDimensions.value, NULL))) WITHIN RECORD AS Datepublished,
MAX(IF (hits.customDimensions.index = 1, hits.customDimensions.value, NULL)) WITHIN RECORD AS Country,
MAX(IF (hits.customDimensions.index = 7, hits.customDimensions.value, NULL)) WITHIN RECORD AS Author,
FROM
(TABLE_DATE_RANGE([storied-toolbox-145015:102152044.ga_sessions_], DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY')))
HAVING Country = 'fr'
正如您所看到的,“诀窍”在于在此处使用have
,而不是WHERE