题解 | #SQL28#

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

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

要换算成秒数来计算

SELECT t1.exam_id,
    ei.duration,
    ei.release_time
FROM (
    SELECT exam_id,
        TIMESTAMPDIFF(SECOND, start_time, submit_time) AS timespent,
        ROW_NUMBER() OVER (PARTITION BY exam_id ORDER BY (SELECT timespent)) AS r_q,
        ROW_NUMBER() OVER (PARTITION BY exam_id ORDER BY (SELECT timespent) DESC) AS r_s
    FROM exam_record
    WHERE submit_time IS NOT NULL
) AS t1
JOIN examination_info ei USING (exam_id)
GROUP BY t1.exam_id
HAVING (SUM(CASE WHEN r_s = 2 THEN timespent ELSE 0 END) - SUM(CASE WHEN r_q = 2 THEN timespent ELSE 0 END)) > 0.5 * ei.duration*60
ORDER BY t1.exam_id DESC

全部评论
为什么第7、8行那,使用order by (select timespent),而不是直接order by timespent
点赞 回复 分享
发布于 2022-04-20 15:13
写法太高端,暂时不敢学😂
点赞 回复 分享
发布于 2023-03-05 11:17 浙江
请问为什么要换算成秒数来计算呢?
点赞 回复 分享
发布于 2023-03-27 19:37 陕西

相关推荐

2024-12-18 12:05
华东师范大学 golang
点赞 评论 收藏
分享
评论
7
1
分享

创作者周榜

更多
牛客网
牛客企业服务