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

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

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

select 
        exam_id,duration,release_time
from
                    (
                        select a.exam_id,a.duration,a.release_time,b.submit_time,
                        timestampdiff(minute,b.start_time,b.submit_time) as diff,
                        row_number() over (partition by a.exam_id order by timestampdiff(minute,b.start_time,b.submit_time) asc) as ranking1,
                        row_number() over (partition by a.exam_id order by timestampdiff(minute,b.start_time,b.submit_time) desc) as ranking2
                        from examination_info a,exam_record b
                        where a.exam_id=b.exam_id and
                        b.submit_time is not NULL
                    ) t1
    group by exam_id
having SUM(
    case 
        when ranking1=2 then -diff
        when ranking2=2 then diff
        else 0
        end )*2 >=duration
ORDER BY exam_id DESC
;

全部评论

相关推荐

qz鹿:*** 祝他毕业就失业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务