在大查询中查询“ in” eventAction数组

时间:2018-10-10 16:13:39

标签: google-analytics google-bigquery

很抱歉,以前是否有人问过这个问题,但是我似乎找不到描述如何执行此操作的特定文档。我们正在将GA数据导入大查询中。我只需要查看我们网站上的访问者已经浏览了两个或更多页面并至少完成了一些操作之一即可。我对BQ相当陌生,并且我已经阅读过有关使用UNNEST的文档,但是不幸的是,这是我在运行此查询时遇到的问题:

SELECT visitId, totals.pageviews  FROM `analytics-acquisition-funnel.119485123.ga_sessions_20181009` WHERE totals.pageviews > 2 AND
'modal-click' IN UNNEST(hits.eventInfo.eventAction) 
order by totals.pageviews DESC LIMIT 100000

我遇到以下问题,不应该这样做。抱歉,我正在阅读此文档,但我觉得用例比大多数显示的要简单: https://cloud.google.com/bigquery/docs/reference/standard-sql/arrays#scanning-arrays

无法访问[2:30]处类型为ARRAY>的值的字段eventInfo

1 个答案:

答案 0 :(得分:1)

以下是用于BigQuery标准SQL

#standardSQL
SELECT visitId, totals.pageviews  
FROM `analytics-acquisition-funnel.119485123.ga_sessions_20181009` 
WHERE totals.pageviews > 2 
AND (SELECT COUNTIF(eventInfo.eventAction = 'modal-click') FROM UNNEST(hits)) > 0 
ORDER BY totals.pageviews DESC 
LIMIT 100000   

OR

#standardSQL
SELECT visitId, totals.pageviews  
FROM `analytics-acquisition-funnel.119485123.ga_sessions_20181009` 
WHERE totals.pageviews > 2 
AND EXISTS(SELECT 1 FROM UNNEST(hits) WHERE eventInfo.eventAction = 'modal-click')
ORDER BY totals.pageviews DESC 
LIMIT 100000