题解 | #最近7天每天的人均停留时长和次均有效时长#

最近7天每天的人均停留时长和次均有效时长

https://www.nowcoder.com/practice/7c0a23de67ad433e9fe6389afabd3496

with cte as (
select uid,vid,unix_timestamp(end_time)-unix_timestamp(start_time)  as secends,
               date(start_time)          as dt,
               max(date(end_time))over() as cur_date 
from user_play_log_tb  )

select dt,round(sum(secends)/count(distinct uid),1) as avg_stay_time_len_user,
          round(ifnull(sum(if(secends>=3,secends,0))/count(secends>=3 or null),0),1) as avg_stay_time_len_once     
from cte
where datediff(cur_date,dt)<=6
group by dt
order by dt

全部评论

相关推荐

尊尼获获:闺蜜在哪?
点赞 评论 收藏
分享
整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务