题解 | #每个6/7级用户活跃情况#

每个6/7级用户活跃情况

https://www.nowcoder.com/practice/a32c7c8590324c96950417c57fa6ecd1

--  计算试卷作答活跃天数
-- select ui.uid,left(start_time,10) 天,
-- 	left(start_time,7) 月,
-- 	left(start_time,4) 年,
-- 	"试卷作答"
-- from user_info ui left join exam_record er
-- 	on ui.uid=er.uid 
-- where `level` in (6,7);
-- 
--  计算答题活跃天数
-- select ui.uid,left(submit_time,10) 天,
-- 	left(submit_time,7) 月,
-- 	left(submit_time,4) 年,
-- 	'题目练习'
-- from user_info ui left join practice_record pr 
-- 	on ui.uid = pr.uid 
-- where `level` in (6,7);

# 合并表格
select uid ,
	count(distinct 月) act_month_total, # 总活跃月份数
	count(distinct if(年=2021,天,null)) act_days_2021, # 2021年活跃天数
	count(distinct if(`试卷作答`='试卷作答' and 年=2021,天,null))	act_days_2021_exam, #2021年试卷作答活跃天数
	count(distinct if(`试卷作答`='题目练习' and 年=2021,天,null)) act_days_2021_question #2021年答题活跃天数
from 
(
(select ui.uid,left(start_time,10) 天,
	left(start_time,7) 月,
	left(start_time,4) 年,
	"试卷作答"
from user_info ui left join exam_record er
	on ui.uid=er.uid 
where `level` in (6,7)) 
union
(select ui.uid,left(submit_time,10) 天,
	left(submit_time,7) 月,
	left(submit_time,4) 年,
	'题目练习'
from user_info ui left join practice_record pr 
	on ui.uid = pr.uid 
where `level` in (6,7))
) as 合并
group by uid 
order by act_month_total desc,act_days_2021 desc;

全部评论

相关推荐

少年郎as:这不把公司名贴出来那我可要喷你了哦
点赞 评论 收藏
分享
notbeentak...:就抓,嗯抓,开不开匿名都要抓,一点坏事不让说,就对公司顶礼膜拜佩服的五体投地就对了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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