0

我需要计算其中具有特定参数的事件。假设,我有参数 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
4

2 回答 2

3

这是你想要的吗?

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;
于 2018-08-02T11:02:15.103 回答
1

如果您在该级别UNNEST()CROSS JOIN超过两列FROM,您将获得重复的行 - 是的。

而不是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` 
于 2018-08-02T08:58:13.293 回答