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

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

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

一看就懂,带注释。

# 1.0 首先从tb_video_info挑选出近一个月的那些视频
with
    t2 as (
        select *
        from tb_video_info
        where date_format(release_time, '%Y-%m-%d') between date_sub((select date_format(max(end_time), '%Y-%m-%d') from tb_user_video_log), interval 29 day) and (select date_format(max(end_time), '%Y-%m-%d') from tb_user_video_log)
    )

# 2.0 明确式子各部分后直接搞定本题
#完播率 avg(if(unix_timestamp(end_time)-unix_timestamp(start_time) >= duration, 1, 0))
#点赞数 sum(if_like)
#评论数 sum(if(comment_id is not null, 1, 0))
#转发数 sum(if_retweet)
#新鲜度 1 / (datediff((select max(end_time) from tb_user_video_log), max(end_time)) + 1)

select 
    t1.video_id,
    round(((100*avg(if(unix_timestamp(end_time)-unix_timestamp(start_time) >= t2.duration, 1, 0))) + (5*sum(if_like)) + (3*sum(if(comment_id is not null, 1, 0))) + (2*sum(if_retweet)))  / (datediff((select max(end_time) from tb_user_video_log), max(end_time)) + 1), 0) as hot_index
from tb_user_video_log as t1
inner join t2
on t1.video_id = t2.video_id
group by t1.video_id
order by hot_index desc
limit 3

全部评论

相关推荐

09-20 22:39
中南大学
故事和酒66:意思就是用了AI辅助也不一定做得出来,还是有区分度,不然他不会让你用的
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务