码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 49. 视频热度问题


    文章目录

          • 实现一
          • 题目来源

    谨以此笔记献给浪费掉的两个小时。

    此题存在多处疑点和表达错误的地方,如果你看到了这篇文章,劝你跳过该题。

    该题对提升HSQL编写能力以及思维逻辑能力毫无帮助。

    实现一
    with info as (
        -- 将数据与 video_info 关联,取出 duration
        select t1.video_id                                           as video_id,
               -- 计算观看时长(s)
               unix_timestamp(end_time) - unix_timestamp(start_time) as view_time,
               if_like,
               if_retweet,
               comment_id,
               duration
        from video_info t1
                 join
             user_video_log t2
             on t1.video_id = t2.video_id
    )
    
    select distinct video_id,
                    -- 计算热度
                    cast(ceil(100 * (seeding_num / video_num) + 5 * like_num + 3 * comment_num +
                              2 * retweet_num) as decimal(16, 1)) as heat
    from (
             -- 计算出每个视频的热度 项
             select video_id,
                    -- 新鲜度(别问我为什么)
                    1                                                                  as freshness,
                    -- 完播数
                    sum(if(view_time = duration, 1, 0)) over (partition by video_id)   as seeding_num,
                    -- 该视频播放次数
                    count(1) over (partition by video_id)                              as video_num,
                    -- 点赞数
                    sum(if_like) over (partition by video_id)                          as like_num,
                    -- 转发数
                    sum(if_retweet) over (partition by video_id)                       as retweet_num,
                    -- 评论数
                    sum(if(comment_id is not null, 1, 0)) over (partition by video_id) as comment_num
             from info
         ) t1
    order by heat desc
    limit 3;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    题目来源

    http://practice.atguigu.cn/#/question/49/desc?qType=SQL

  • 相关阅读:
    CloudService计算类技术和网络类技术以及存储类技术的基础学习
    Zookeeper与Hadoop集群的启动的不同点
    浅谈智能安全配电装置在老年人建筑中的应用
    EXCEL 打印设置公共表头
    2024华为OD机试真题-伐木工-(C++/Python)-C卷D卷-200分
    sklearn快速入门教程:处理分类型数据
    Kibana-8.4.0-Linux安装
    火爆全网的头戴式耳机,Y2K辣妹时髦单品——Umelody轻律 U1头戴式耳机!
    Java IDEA maven 配置
    CountDownLatch闭锁原理解析
  • 原文地址:https://blog.csdn.net/weixin_43676735/article/details/132783178
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号