题解 | #每天的日活数及新用户占比#
每天的日活数及新用户占比
https://www.nowcoder.com/practice/dbbc9b03794a48f6b34f1131b1a903eb
select
b.dt,
count(b.uid) dau,
round(count(a.uid)/count(b.uid),2) uv_new_ratio
from
(
select
uid,
min(date(in_time)) dt
from tb_user_log
group by uid
) a # 新用户首次登陆日期
right join
(
select uid, date(in_time) dt from tb_user_log
union
select uid, date(out_time) from tb_user_log
# 使用union去重合并登入登出表!!! 而不是用union all(不去重)
# 用户使用总表
) b
on a.uid = b.uid and a.dt = b.dt
group by b.dt
order by b.dt
表B:
表A拼B:

