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
全部评论
相关推荐
09-27 08:41
门头沟学院 嵌入式软件工程师 点赞 评论 收藏
分享