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

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

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

全部评论

相关推荐

11-14 16:13
已编辑
重庆科技大学 测试工程师
Amazarashi66:不进帖子我都知道🐮❤️网什么含金量
点赞 评论 收藏
分享
可可可可可_:nb啊,看样子是专科玩了几年随便专升本了个民办,又玩了两年。你这能找到我吃
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务