在bigquery中关闭渠道,以获取在几天范围内每天分组的两个事件之间的结果

时间:2019-04-07 16:49:46

标签: google-bigquery

我试图在几天内每天在Google bigquery中的两个事件(按用户计算)之间创建一个封闭的渠道。

我在此article

中尝试了该方法

我设法一天获得了两个事件的渠道代码,但是在分组时,每天相同的代码在几天的时间范围内都会产生错误的结果。

这是我正在使用的代码:

SELECT 
COUNT(DISTINCT funnel_1) AS f1_users, 
  COUNT(DISTINCT funnel_2) AS f2_users,df as dates
FROM (
  SELECT
  IF (event_name = "event1",dv,NULL) as funnel_1, 
  IF (event_name = "event1" AND next_event = "event2",dv, NULL) AS funnel_2,SELECT COUNT(DISTINCT funnel_1) AS f1_users, 
  COUNT(DISTINCT funnel_2) AS f2_users,df as dates
FROM (
  SELECT
  IF (event_name = "event1",dv,NULL) as funnel_1, 
  IF (event_name = "event1" AND next_event = "event2",dv, NULL) AS funnel_2,
  df
  FROM (
    SELECT event_name,device.advertising_id as dv , event_timestamp,event_date as df,
    LEAD(event_name, 1) OVER (PARTITION BY device.advertising_id ORDER BY event_timestamp) AS next_event
    FROM `main_table_151454888.events_201903*`

    WHERE _TABLE_SUFFIX between '12' and '31' and 
    event_name = "event1" OR event_name = "event2"
    ORDER BY 2,3 
  )
)
group by dates
order by dates

有什么想法我可以更改此代码以使其不仅可以工作一天,而且可以工作几天?

0 个答案:

没有答案