题解 | #牛客直播各科目出勤率#

牛客直播各科目出勤率

http://www.nowcoder.com/practice/0cab547df4f0430b93042128f445d899

分步查询然后相除即可

select
  ct.course_id,
  ct.course_name,
  round(M.mn * 100 / N.sn, 2)
from
  course_tb ct
  left join (
    select
      bt.course_id,
      sum(if_sign) sn
    from
      behavior_tb bt
    group by
      bt.course_id
  ) N on ct.course_id = N.course_id
  left join (
    select
      distinct count(user_id) OVER(
        PARTITION BY course_id
        order by
          course_id
      ) mn,
      course_id
    from
      attend_tb
    group by
      course_id,
      user_id
    having
      sum(TIMESTAMPDIFF(MINUTE, in_datetime, out_datetime)) >= 10
  ) M on M.course_id = N.course_id
order by
  ct.course_id
全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务