0

我已经计算了滚动活跃用户(每周)如下:

    SELECT
      DATE_TRUNC(EXTRACT(DATE FROM tracks.timestamp), WEEK),
      COUNT(DISTINCT tracks.user_id)
    FROM `company.dataset.tracks` AS tracks
    WHERE tracks.timestamp > TIMESTAMP('2020-01-01')
    AND tracks.event = 'activation_event'
    GROUP BY 1
    ORDER BY 1

我有兴趣了解每周滚动执行第一次激活事件的不同用户的数量。

4

2 回答 2

1

If I follow you correctly, you can use two levels of aggrgation:

select 
    date_trunc(date(activation_timestamp), week) activation_week, 
    count(*) cnt_active_users
from (
    select min(timestamp) activation_timestamp
    from `company.dataset.tracks` t
    where event = 'activation_event'
    group by user_id
) t
where activation_timestamp > timestamp('2020-01-01

The subquery comptes the date of the first activation event per user, then the outer query counts the number of such events per week.

于 2020-11-14T10:44:47.607 回答
1

如果您希望在同一个查询中同时激活和启动:

SELECT week, COUNT(*) as users_in_week,
       COUNTIF(seqnum = 1) as new_users
FROM (SELECT DATE_TRUNC(EXTRACT(DATE FROM t.timestamp), WEEK) as week,
             t.user_id, COUNT(*) as cnt,
             ROW_NUMBER() OVER (PARTITION BY t.user_id ORDER BY MIN(t.timestamp)) as seqnum
      FROM `company.dataset.tracks` t
      WHERE t.event = 'activation_event'
      GROUP BY 1, 2
     ) t
WHERE tracks.timestamp > TIMESTAMP('2020-01-01')
GROUP BY 1
ORDER BY 1;
于 2020-11-14T12:41:24.830 回答