题解 | #分别满足两个活动的人#

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

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

用的最原始的方法,即得到一张表,含有exam_id、duration、release_time、第二长和第二短的作答时间,然后只需计算两者之差与duration的一半比较即可。

select exam_id,duration,release_time
/*开始构建表格*/
from (
    select exam_id,release_time,duration from examination_info
) A 
left join 
(
    select exam_id,du
    from (
        select exam_id,timestampdiff(minute,start_time,submit_time) du,row_number() over(partition by exam_id order by timestampdiff(minute,start_time,submit_time)) rn_1
        from exam_record ) X  
        where rn_1 = 2
) B using(exam_id)
left join
(
    select exam_id, du_1
    from (
        select exam_id,timestampdiff(minute,start_time,submit_time) du_1,row_number() over(partition by exam_id order by timestampdiff(minute,start_time,submit_time) desc) rn_2
        from exam_record ) Y 
        where rn_2 = 2
) C using(exam_id)
/*完成构建表格*/
where du_1 - du > 0.5*duration
order by exam_id desc
全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
06-04 18:37
门头沟学院 Java
勇敢的ssr求对象:前面看的有点奔溃,看到只有你是真玩啊,忍不住笑出了声😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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