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

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

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

select 
exam_id
,duration
,release_time
-- ,sum(big)
-- ,sum(small)
from
(
  select
t.exam_id
,duration
,release_time
,dif big
,0   small
from 
(
select
a.exam_id
,duration
,release_time
,timestampdiff(minute,start_time,submit_time) dif
-- ,row_number()over(partition by  a.exam_id order by timestampdiff(minute,start_time,submit_time) ) rn 
 ,row_number()over(partition by  a.exam_id order by timestampdiff(minute,start_time,submit_time) desc) rn1 
from exam_record a 
left join examination_info b on a.exam_id=b.exam_id
where submit_time is not null
) t
where rn1=2
union all
select
t.exam_id
,duration
,release_time
,0
,dif
from 
(
select
a.exam_id
,duration
,release_time
,timestampdiff(minute,start_time,submit_time) dif
,row_number()over(partition by  a.exam_id order by timestampdiff(minute,start_time,submit_time) ) rn 
,row_number()over(partition by  a.exam_id order by timestampdiff(minute,start_time,submit_time) desc) rn1 
from exam_record a 
left join examination_info b on a.exam_id=b.exam_id
where submit_time is not null
) t
where rn=2
  
) t1
group by exam_id
,duration
,release_time
having sum(big)-sum(small)>=max(duration)/2
order by exam_id desc



#MySQL#
全部评论

相关推荐

不愿透露姓名的神秘牛友
11-26 18:54
说等下个版本吧的发呆爱好者很贪睡:佬最后去了哪家呀
点赞 评论 收藏
分享
ProMonkey2024:5个oc?厉害! 但是有一个小问题:谁问你了?😡我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了(别的帖子偷来的,现学现卖😋)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务