我想检索在访问分割日期内有自定义尺寸匹配的访问量。 我在这个查询的帮助下得到这些数据作为所有选定日期的总和,但是如何按日期分割它?
非常感谢提前!
select sum(sessions) as total_sessions, from (
select
fullvisitorid,
count(distinct visitid) as sessions,
from (TABLE_DATE_RANGE([XXX.ga_sessions_], TIMESTAMP('2016-09-01'), TIMESTAMP('2016-09-03')))
where totals.visits = 1
AND hits.customDimensions.index = 3
AND hits.customDimensions.value = 'play'
group each by fullvisitorid
)
答案 0 :(得分:0)
您可以使用standard SQL在桌面上尝试此操作(取消选中“显示选项”下的“使用旧版SQL”)吗?我可能误解了这个问题,但它计算了每天与customDimensions
条件相匹配的总访问次数,我相信这就是你想要的。
SELECT
_PARTITIONTIME,
COUNTIF(EXISTS (SELECT 1 FROM UNNEST(hits), UNNEST(customDimensions)
WHERE index = 3 AND value = 'play')) as sessions
FROM `XXX.ga_sessions_*`
WHERE totals.visits = 1
GROUP BY _PARTITIONTIME;
答案 1 :(得分:0)
ga_sessions表包含date
字段(请参阅Analytics to BigQuery Export schema)
因此,如果您希望继续使用BigQuery Legacy SQL进行上述查询,则可以使用此date
字段,如下例所示
SELECT date, SUM(sessions) AS total_sessions FROM (
SELECT
date,
fullvisitorid,
COUNT(DISTINCT visitid) AS sessions
FROM (TABLE_DATE_RANGE([XXX.ga_sessions_], TIMESTAMP('2016-09-01'), TIMESTAMP('2016-09-03')))
WHERE totals.visits = 1
AND hits.customDimensions.index = 3
AND hits.customDimensions.value = 'play'
GROUP BY date, fullvisitorid
)
GROUP BY date
如果您可以/希望Migrate from BigQuery Legacy SQL到BigQuery Standard SQL,您可以使用以下示例:
SELECT
_TABLE_SUFFIX AS date,
COUNTIF(EXISTS (SELECT 1 FROM UNNEST(hits), UNNEST(customDimensions)
WHERE TRUE OR (index = 3 AND value = 'play'))) AS sessions
FROM `XXX.ga_sessions_*`
WHERE totals.visits = 1
AND _TABLE_SUFFIX BETWEEN '2016-09-01' AND '2016-09-03'
GROUP BY date
查看有关使用Wildcard Tables
的详细信息