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
全部评论
相关推荐
nlhxq🌱:就这样的就业形势,这些畜牲学校领导还卡着不让去实习。人家秋招你实习,人家入职你打灰 点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
查看20道真题和解析