题解 | #每个6/7级用户活跃情况#

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

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

select
  e.exam_id,
  e.duration,
  release_time
from
  (
    select
      t.exam_id,
      max(
        case
          when fastt = 2 then timediff
        end
      ) as fast_2,
      max(
        case
          when sloww = 2 then timediff
        end
      ) as slow_2
    from
      (
        select
          *,
          timestampdiff(second, start_time, submit_time) as timediff,
          dense_rank() over(
            partition by exam_id
            order by
              timestampdiff(second, start_time, submit_time) desc
          ) as fastt,
          dense_rank() over(
            partition by exam_id
            order by
              timestampdiff(second, start_time, submit_time)
          ) as sloww
        from
          exam_record
        where
          submit_time is not null
      ) as t
    group by
      t.exam_id
  ) as t
  join examination_info as e using(exam_id)
where
  (fast_2 - slow_2) >= 0.5 * 60 * duration
order by
  exam_id desc

用了两次子查询: 注意本题是在所有试卷的第二快和第二慢完成答题的人数中找出每类试卷的两个用时之差大于0.5duration的,而不是第二快和第二慢用时之差; 首先在recored表中把用时之差、用时最快排名、最慢排名组成新表; 其次筛选出rank=2的第二快和第二慢的时间; 最后筛选出作差大于0.5duration并链接试卷信息表按exam_id降序排序。

全部评论

相关推荐

每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
感觉他们一点都不了解现在这个社会就业有多难,已经在牛客刷到好多篇 延毕的帖子了,延毕就会导致已经找好的工作就没了,还得重新再找,学校和老师们是怎么想的呢????看到学生丢失工作会开心吗 就业数据都在造假,真实的就业困难不去解决 一个个真是好样的
从今天开始狠狠卷JVAV_癫:学生看到的是导师不放实习导致offer黄了。 导师看到的是招进来的学生吃自己补助和自己的招生名额,却没给自己升迁带来任何帮助,还要跑路。 根本利益的不一致,最主要留校的导师大概率是职场上招聘失败的,被迫留校的,什么牛鬼蛇神都会有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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