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

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

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之后使用子查询。

全部评论

相关推荐

05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
程序员小白条:太晚了,看别人找到实习了才投的话,自己本身就没啥准备,计划太晚咯,只能吞苦果子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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