SQL166大厂面试真题
统计新用户的方法,判断用户最早登陆日期是否等于当前日期,是记为1。sum(if(new_user_time=time,1,0))
select time, count(distinct t1.uid)dau, round(sum(if(new_user_time=time,1,0))/count(distinct t1.uid) ,2)from
(
select uid, date(in_time) as time from tb_user_log union
select uid, date(out_time) as time from tb_user_log
)t1 join
(
select uid, min(date(in_time))new_user_time from tb_user_log
group by uid
)t2 using(uid)
group by time
order by time ASC
#笔试#