题解 | #第二快/慢用时之差大于试卷时长一半的试卷#

第二快/慢用时之差大于试卷时长一半的试卷

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

select
    exam_id,
    duration,
    release_time
from
    (
        select
            t1.exam_id,
            e.duration,
            e.release_time,
            sum(
                case
                    when t1.rank_desc = 2 then t1.time_diff
                    when t1.rank_asc = 2 then - t1.time_diff
                    else 0
                end
            ) as sum_time
        from
            (
                select
                    exam_id,
                    timestampdiff (minute, start_time, submit_time) as time_diff,
                    row_number() over (
                        partition by
                            exam_id
                        order by
                            timestampdiff (minute, start_time, submit_time) desc
                    ) rank_desc,
                    row_number() over (
                        partition by
                            exam_id
                        order by
                            timestampdiff (minute, start_time, submit_time) asc
                    ) rank_asc
                from
                    exam_record
                where
                    submit_time is not null
            ) t1
            left join examination_info e on t1.exam_id = e.exam_id
        group by
            t1.exam_id
    ) t2
where
    sum_time >= duration / 2
order by
    exam_id desc

全部评论

相关推荐

钱嘛数字而已:辅导员肯定不能同意,不然你出事了,他要承担责任。但是,脚和脑子都长在你自己身上,使用它还需要向辅导员报告么? 辅导员必须按流程拒绝你,然后你拿出成年人的态度,做自己的选择。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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