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

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

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

SELECT DISTINCT video_id, 
ROUND((100*(watch/play_v)+5*like_num+3*comment_num+2*retweet_num)*(1/(DATEDIFF(maxdate,groupmaxdate)+1))) AS hot_index
FROM(
    SELECT *,
    MAX(simdate) OVER () AS maxdate,
    MAX(simdate) OVER (PARTITION BY video_id) AS groupmaxdate,
    SUM(IF(viewtime>=duration,1,0)) OVER (PARTITION BY video_id) AS watch,
    COUNT(video_id) OVER (PARTITION BY video_id) AS play_v
    FROM(
            SELECT ul.video_id, vi.duration,
            DATE_FORMAT(ul.end_time, '%Y-%m-%d') AS simdate,
            TIME_TO_SEC(TIMEDIFF(ul.end_time, ul.start_time)) AS viewtime,
            SUM(if_like) OVER (PARTITION BY video_id) AS like_num,
            SUM(if_retweet) OVER (PARTITION BY video_id) AS retweet_num,
            COUNT(comment_id) OVER (PARTITION BY video_id) AS comment_num
            FROM tb_user_video_log ul
            JOIN tb_video_info vi USING(video_id)
            WHERE DATEDIFF((SELECT MAX(end_time) FROM tb_user_video_log) , vi.release_time) <=29
            ) AS t
    ) AS t2
ORDER BY hot_index DESC
LIMIT 3

知识点速记:WHERE DATEDIFF((SELECT MAX(end_time) FROM tb_user_video_log) , vi.release_time) <=29

理解题目本身比写出代码更复杂

全部评论

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:48
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务