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

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

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


with table1 as(
    select exam_id,
    duration,
    timestampdiff(minute,start_time,submit_time) as time,release_time
    from exam_record left join examination_info using(exam_id)
    where submit_time is not null
),
table2 as (
    select exam_id,time,
    row_number() over(partition by exam_id order by time desc) as desc_time,
    row_number() over(partition by exam_id order by time) as asc_time,
    duration , release_time
    from table1
),
table3 as (
select exam_id,duration,release_time, 
sum(case when desc_time = 2 then time 
         when asc_time = 2 then -time
         else 0 
         end) as sum_time
from table2
group by exam_id,duration,release_time
having sum_time >= duration*0.5
order by exam_id desc
)
select exam_id,duration,release_time
from table3

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-26 20:06
点赞 评论 收藏
分享
牛客722552937号:新锐之星有点坑爹,特别是对男的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务