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

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

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

select 
    exam_id,
    duration,
    release_time
from 
(
    select
    er.exam_id,
    ei.duration,
    release_time,
    timestampdiff(second,start_time,submit_time) as exam_time,
    row_number() over(partition by ei.exam_id order by timestampdiff(second,start_time,submit_time)) r1,
    row_number() over(partition by ei.exam_id order by timestampdiff(second,start_time,submit_time) desc) r2
    from exam_record er
    inner join examination_info ei
    on er.exam_id = ei.exam_id
    where er.score is not null
) a
group by exam_id
having (max(if(r2=2,exam_time,0)) - max(if(r1=2,exam_time,0))) >= duration/2
思路是这样的,但是不知道max还能这样用,瞬间好像知道mysql的逻辑了
order by exam_id desc

#实习,不懂就问##小米提前批笔试难吗##牛客创作赏金赛##央国企投递记录##神州信息工作体验#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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