计算新用户和返回用户的时间范围
我得到了一个类似的数据集:
我想计算新的用户,并在那里返回不同的时间范围,但是那里返回时是 user_id 的重复。例如: 我得到了这样的数据:
,
时间范围为15/12/2021至20/12/ 2021,
输出:2个新用户,2个返回用户。
我使用SQL Clickhouse和Superset可视化。
我的编码尝试:
WITH data AS (
SELECT user_id,
created_time,
MIN(created_time) OVER (PARTITION BY user_id) AS first_time,
ROW_NUMBER() OVER(PARTITION BY user_id) AS no_login
FROM default.active_user
), data2 AS (
SELECT *,
(CASE WHEN no_login=1 THEN 'new' ELSE 'returning' END) AS category_user
FROM data
)
SELECT user_id,
COUNT(distinct user_id) AS active_user,
category_user,
created_time
FROM data2
GROUP BY user_id,
category_user,
created_time
I got a dataset like this:
I want to count new and returning users with different time ranges, but there are duplicates of user_id in returning. For example:
I got a data like this:
with a time range from 15/12/2021 to 20/12/2021,
the output: 2 new users, 2 returning users.
I use SQL clickhouse and superset for visualizing.
My coding attempt:
WITH data AS (
SELECT user_id,
created_time,
MIN(created_time) OVER (PARTITION BY user_id) AS first_time,
ROW_NUMBER() OVER(PARTITION BY user_id) AS no_login
FROM default.active_user
), data2 AS (
SELECT *,
(CASE WHEN no_login=1 THEN 'new' ELSE 'returning' END) AS category_user
FROM data
)
SELECT user_id,
COUNT(distinct user_id) AS active_user,
category_user,
created_time
FROM data2
GROUP BY user_id,
category_user,
created_time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论