题解 | 近一个月发布的视频中热度最高的top3视频

近一个月发布的视频中热度最高的top3视频

https://www.nowcoder.com/practice/0226c7b2541c41e59c3b8aec588b09ff

请问哪里错了呢 可以运行 但答案不对

with t1

as(select uid

    ,u.video_id

    ,if_like

    ,comment_id

    ,if_retweet

    ,CASE

        WHEN time_diff >= duration THEN 1

        ELSE 0

    END AS end_video

    from(select uid

            ,if_like

            ,comment_id

            ,if_retweet

            ,video_id

            ,timestampdiff(SECOND,start_time,end_time) time_diff

        from tb_user_video_log) u

        join tb_video_info v on u.video_id=v.video_id

    order by video_id,uid)

select t1.video_id

,round((100*sum(end_video)/count(end_video)+5*count(case when end_video=1 then if_like else 0 end)+3*count(case when end_video=1 then comment_id else 0 end)+2*count(case when end_video=1 then if_retweet else 0 end))*(1/(no_time+1)) ) hot_index

from t1 left join (

                    select video_id

                    ,DATEDIFF((select max(end_time) from tb_user_video_log), max(end_time)) no_time

                    from tb_user_video_log

                    group by video_id) t2 on t1.video_id=t2.video_id

group by video_id

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务