题解 | #每天的日活数及新用户占比#
每天的日活数及新用户占比
https://www.nowcoder.com/practice/dbbc9b03794a48f6b34f1131b1a903eb
这题比较简单,话不多说,上代码!优雅~
<参考代码>
SELECT dt,count(distinct uid)dau,round(sum(if(dt=min_date,1,0))/count(distinct uid),2)uv_new_ratio FROM (SELECT uid,date(in_time) dt FROM tb_user_log UNION SELECT uid,date(out_time) dt FROM tb_user_log)a LEFT JOIN (SELECT uid,min(date(in_time)) min_date FROM tb_user_log GROUP BY uid)b USING(uid) GROUP BY dt ORDER BY dt;<运行结果>