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

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

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
08-14 22:16
我爱加瓦233:今年行情真的好起来了,暑期实习拿了美团,京东,饿了么三家的Offer,最终去了美团,披上了我的黄马褂,开启送外卖之旅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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