如何在 Google BigQuery 中使用 UNNEST 函数获取 COUNT?

How to get COUNT with UNNEST function in Google BigQuery?

我需要获取其中包含特定参数的事件的计数。比方说,我有参数 event_notification_received 和参数(类型、标题、code_id)。在参数 code_id 中 - 我有唯一的广告名称。我需要计算使用此类参数接收到的事件数量。我正在使用 UNNEST 函数来访问事件的参数。但是它在执行后给出了太多的结果,我认为这是因为 UNNEST 功能。我怎样才能正确计算事件?谢谢。

这是我的标准 SQL 查询:

#standardSQL
SELECT event_date, event_timestamp, event_name, user_id, app_info.version, 
geo.country, geo.region, geo.city,  
my_event_params, 
user_prop,
platform
FROM 
`myProject.analytics_199660162.events_201807*`,
UNNEST(event_params) as my_event_params,
UNNEST(user_properties) as user_prop

WHERE
_TABLE_SUFFIX BETWEEN '24' AND '30' AND
event_name = "event_notification_received"

AND
my_event_params.value.string_value = "my_adverticement_name"

AND
platform = "ANDROID"

ORDER BY event_timestamp DESC

如果 UNNEST()CROSS JOINFROM 级别超过两列,您将得到重复的行 - 是的。

而不是 UNNEST()SELECT 级别,只是为了提取和 COUNT 您要查找的值:

SELECT COUNT(DISTINCT (
    SELECT value.string_value FROM UNNEST(user_properties) WHERE key='powers')
  ) AS distinct_powers
FROM `firebase-sample-for-bigquery.analytics_bingo_sample.events_20160607` 

这是你想要的吗?

SELECT . . .,
       (SELECT COUNT(*)
        FROM UNNEST(event_params) as my_event_params
        WHERE my_event_params.value.string_value = 'my_adverticement_name'
       ) as event_count
FROM `myProject.analytics_199660162.events_201807*`,
      UNNEST(user_properties) as user_prop
WHERE _TABLE_SUFFIX BETWEEN '24' AND '30' AND
      event_name = 'event_notification_received' AND
      platform = 'ANDROID'
ORDER BY event_timestamp DESC;