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

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

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

select
    dt,
    round(sum(times) / count(distinct uid),1) as avg_stay_time_len_user,
    case when max(times)<3 then 0.0 else (round(sum(case when times>3 then times end) / count(case when times>3 then uid end),1)) end as avg_stay_time_len_once
from
    (
        select
            uid,
            vid,
            date_format (start_time, '%Y-%m-%d') as dt,
            timestampdiff(day,start_time,(select max(start_time) from user_play_log_tb)) as days,
            timestampdiff (second, start_time, end_time) as times
        from
            user_play_log_tb
    ) t
where days<7
group by
    dt

全部评论

相关推荐

joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:46
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务