这题算是比较简单的了,这次求新顾客用的累计次数和为1 而不是链接的方法,算是一种新的思路了,大家可以看一看! 因为之前已经说过了如何进行日期的拆分和求顾客的登录次数,说以不在赘述,代码如下

select date,count(uid) as dau,
    round( sum(if(times=1,1,0))/count(uid) ,2)
from
(select *,count(*) over (partition by uid order by date ) as times
from
(select uid,left(in_time,10) as date
from tb_user_log
union 
SELECT uid,left(out_time,10) as date
from tb_user_log) tmp) base
GROUP by date
order by date