题解 | #平均播放进度大于60%的视频类别#

平均播放进度大于60%的视频类别

https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef

select tag, avg_play_progress
from (
    select tag, CONCAT(FORMAT(AVG(play_progress)*100, 2),'%') as avg_play_progress
    from (
        select uid, tag, 
        (case when watch_time >= duration then 1
        else watch_time/duration end) as play_progress
        from (
            select uid, a.video_id,
            TIMESTAMPDIFF(SECOND, start_time, end_time) as watch_time, tag, duration
            from tb_user_video_log as a
            left join tb_video_info as b
            on a.video_id = b.video_id
        ) as c
    ) as d
    group by tag
    order by avg_play_progress desc
) as e
where CAST(SUBSTRING(avg_play_progress, 1, LENGTH(avg_play_progress)-1) AS DECIMAL(5,2)) > 60.00;

全部评论
1,将整数转换成字符串类型的百分数形式:使用FORMAT,然后使用拼接函数将%进行拼接到后面; 2,字符串类型的数字形式与整数进行比较:使用SUBSTRING将数字类型的字符串提取出来,用CAST函数转为整形,然后进行比较。
点赞 回复 分享
发布于 2023-08-02 23:59 江苏

相关推荐

熊大不大:微信也是华为旗下吧,我看我朋友也是华为工牌写wx
点赞 评论 收藏
分享
已注销:bro不如吃顿疯狂星期四
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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