SQL188 牛客直播各科目出勤率
首先需要对attend_tb表进行预处理,把一天内多次登录的数据只保留一条数据,避免出现重复计算,同时筛选出观看时长大于等于10的数据
with t1 as (
select distinct
user_id,course_id
from
attend_tb
where
timestampdiff(minute,in_datetime,out_datetime)>=10
)
select
behavior_tb.course_id
,course_name
,round(count(t1.user_id)*100/sum(if_sign),2) `attend_rate(%)`
from
course_tb right join behavior_tb on course_tb.course_id=behavior_tb.course_id
left join t1 on behavior_tb.course_id=t1.course_id and
behavior_tb.user_id=t1.user_id
group by
behavior_tb.course_id,course_name
order by
course_id asc
with t1 as (
select distinct
user_id,course_id
from
attend_tb
where
timestampdiff(minute,in_datetime,out_datetime)>=10
)
select
behavior_tb.course_id
,course_name
,round(count(t1.user_id)*100/sum(if_sign),2) `attend_rate(%)`
from
course_tb right join behavior_tb on course_tb.course_id=behavior_tb.course_id
left join t1 on behavior_tb.course_id=t1.course_id and
behavior_tb.user_id=t1.user_id
group by
behavior_tb.course_id,course_name
order by
course_id asc
全部评论
相关推荐
10-24 14:58
郑州大学 Java 点赞 评论 收藏
分享
09-04 20:39
南京林业大学 机械工程师
阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行 点赞 评论 收藏
分享
