题解 | #计算每天的新用户占比#
计算每天的新用户占比
https://www.nowcoder.com/practice/c95ddc4968044035853c22e000a0ec21
建议在使用表前,进行一下去重,不然计算的时候可能会不准确
思路:
- 先算出每个用户最早的活跃日期
- 利用表链接,得到大表 分原始表 t和最早活跃表t1
- 统计原始表即活跃数量,统计最早活跃表即新增用户数量
- 计算即可
select t.login_date as dt, count(t.uid) as total_user_num, concat(round(count(t1.uid)/count(t.uid)*100,1),'%') as new_user_rate from (select distinct uid,login_date from user_login_tb) t left join (select uid,min(login_date) as login_date from user_login_tb group by uid )t1 using(uid,login_date) group by t.login_date order by dt