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

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

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

select
    tbb.tag,
    tbb.avg_play_progress
from
    (
        select
            tb.tag,
            concat (
                format (
                    (
                        case
                            when sum(rate) / count(tb.video_id) > 0.6 then sum(rate) / count(tb.video_id) * 100
                            else null
                        end
                    ),
                    2
                ),
                '%'
            ) as avg_play_progress
        from
            (
                select
                    a.video_id,
                    b.tag,
                    (
                        case
                            when TIMESTAMPDIFF (SECOND, start_time, end_time) >= duration then 1
                            when TIMESTAMPDIFF (SECOND, start_time, end_time) / b.duration < 1 then TIMESTAMPDIFF (SECOND, start_time, end_time) / b.duration
                            else null
                        end
                    ) as rate
                from
                    tb_user_video_log a
                    inner join tb_video_info b on a.video_id = b.video_id
            ) as tb
        group by
            tb.tag
    ) as tbb
where
    tbb.avg_play_progress is not null
order by
    tbb.avg_play_progress desc

这题需要注意

1.两个时间直接相减运算是不行的,要定单位为秒,用这个函数`TIMESTAMPDIFF`(一开始我就是用时间相减,结果算出来旅游那里不行)

2.我用的外层的case语句,最后会选出旅行为空的行,所以再加了一层select语句筛选不为空的行。(暂时没想到去空的函数,所以用了select语句方便)

全部评论

相关推荐

牛客78682892...:直接点还好,总比要了简历也不回的强
点赞 评论 收藏
分享
算法冲刺中:kpi面加一,面完完全没动静,感谢信都没有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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