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

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

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

select exam_id,duration,release_time from
(select t2.exam_id,
t2.duration,
t2.release_time,
timestampdiff(minute,start_time,submit_time) cnt,
dense_rank() over(partition by exam_id order by timestampdiff(second,start_time,submit_time)) as rank_asc,
dense_rank() over(partition by exam_id order by  timestampdiff(second,start_time,submit_time) desc ) as rank_desc
from exam_record t1 join
examination_info t2 on t1.exam_id = t2.exam_id
where submit_time is not null) as temp1
group by exam_id 
having sum(if (rank_desc=2,cnt,0)) -sum(if (rank_asc=2,cnt,0)) >=duration/2
order by exam_id desc

  • 这里最巧妙的是第12行。
  • from之后使用子查询。

全部评论

相关推荐

2024-12-26 20:46
复旦大学 C++
国棉17厂丶小王:拿了offer的那个周末晚上去网吧通宵,去网吧不知道玩什么刷了lc的每日一题,然后试着第一次打开了三角洲行动,从此少了一个已经刷了700道题的lc用户,但是烽火地带多了一只🐭🐭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务