题解 | #计算每天的新用户占比#
计算每天的新用户占比
https://www.nowcoder.com/practice/c95ddc4968044035853c22e000a0ec21
select
t.login_date as dt,
count(t.uid) as total_user_num,
concat (
round(sum(is_new) * 100 / count(t.uid), 1),
'%'
) as new_user_rate
from
(
select
distinct u.uid,
u.login_date,
if (u.login_date = f.first_date, 1, 0) as is_new
from
user_login_tb u
left join (
select
distinct uid,
min(login_date) as first_date
from
user_login_tb
group by
uid
) f on u.uid = f.uid
) t
group by
dt
order by
dt;

