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

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

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

SELECT DISTINCT exam_id,duration,release_time
FROM(
    SELECT exam_id,duration,release_time,
    SUM(CASE WHEN rank1 = 2 THEN time WHEN rank2 = 2 THEN -time ELSE 0 END) AS sub
    FROM(
        SELECT a.exam_id,duration,release_time,
        TIMESTAMPDIFF(minute,start_time,submit_time) as time,
        row_number()OVER(PARTITION BY a.exam_id ORDER BY TIMESTAMPDIFF(minute,start_time,submit_time)DESC) AS rank1,
        row_number()OVER(PARTITION BY a.exam_id ORDER BY TIMESTAMPDIFF(minute,start_time,submit_time)) AS rank2
        FROM exam_record a
        LEFT JOIN examination_info b
        ON a.exam_id = b.exam_id
        WHERE submit_time IS NOT NULL
    )t1
    GROUP BY exam_id
)t2
WHERE sub*2 >= duration
ORDER BY exam_id DESC

# ### 时间差TIMESTAMPDIFF(minute,start_time,submit_time) as time
# ### 排序第二快:row_number()OVER(PARTITION BY exam_id ORDER BY time DESC) AS rank1
# ### 排序第二慢:row_number()OVER(PARTITION BY exam_id ORDER BY time) AS rank2
# SELECT a.exam_id,duration,release_time,
# FROM exam_record a
# LEFT JOIN examination_info b
# ON a.exam_id = b.exam_id
# WHERE submit_time IS NOT NULL

# SUM(CASE WHEN rank2 = 2 THEN time THEN WHEN rank1 = 2 THEN -time ELSE 0 END) AS sub

全部评论

相关推荐

找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务