题解 | #每天的日活数及新用户占比#

每天的日活数及新用户占比

https://www.nowcoder.com/practice/dbbc9b03794a48f6b34f1131b1a903eb

select date(a.in_time) as dt,
       count(distinct a.uid) as dau,
	   #如果b.uid有值,则说明当前日期是用户首次登陆日期
       round(count(case when b.uid is not null then 1 end)/count(distinct a.uid),2) as uv_new_ratio
from
# 将两个时间字段纵向合并
(select a1.uid,a1.in_time from tb_user_log a1 
union select a2.uid,a2.out_time as in_time from tb_user_log a2) a
left join
# 计算用户首次登陆日期
(select uid,min(in_time) as first_time from tb_user_log group by uid) b
on a.uid=b.uid and a.in_time=b.first_time
group by dt
order by dt asc

全部评论

相关推荐

01-12 17:45
门头沟学院 Java
叁六玖:这样的应该钱不多,以前我也被问,我在问他们实习公工资多少,一般都是2200-2800
找实习记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务