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

牛客直播各科目出勤率

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

with t1 as(
    select user_id,
            course_id,
            if_sign,
            round(sum(timestampdiff(second,in_datetime,out_datetime))/60,1) onlinetime
    from attend_tb right join behavior_tb using(user_id,course_id)
    group by user_id,course_id,if_sign
)

select course_id,
        course_name,
        round(sum(if(onlinetime >= 10,1,0))/count(1)*100,2) "attend_rate(%)"
from t1 join course_tb using(course_id)
where  if_sign = 1
group by course_id,course_name

先统计用户每节课的在线时间,在统计出勤率

问题:统计用户每节课的在线时间时,由于attend_tb联合了behavior_tb,必须有behavior_tb的全部数据,因为可能用户报名了但没有出席,从而出现缺人

全部评论

相关推荐

投递京东等公司10个岗位
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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