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

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

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

with 
user_info as 
    (select uid from user_info  where level in (6,7)),
examination_info as 
    (select exam_id from examination_info),
union_table as
    (select uid,start_time as time,exam_id as eq  from exam_record
    union all 
    select uid,submit_time as time,question_id as eq from practice_record)

select
    t1.uid,
    count(distinct date_format(t2.time,'%Y%m')) as act_month_total,
    count(distinct case when year(t2.time) = 2021 then date_format(t2.time,'%m%d') else null end ) as act_days_2021,
    count(distinct case when (year(t2.time) = 2021 and t2.eq in (select exam_id from examination_info)) then date_format(t2.time,'%m%d') else null end) as act_days_2021_exam,
    count(distinct case when (year(t2.time) = 2021 and t2.eq not in (select exam_id from examination_info)) then date_format(t2.time,'%m%d') else null end) as act_days_2021_question
from
    user_info t1
left join
    union_table t2
on 
    t1.uid = t2.uid
group by
    t1.uid
order by
    act_month_total desc,act_days_2021 desc

全部评论

相关推荐

05-23 19:33
重庆大学 Java
只学了传统后端,马上去后端实习了,在想要不要学习agent开发相关的。27秋招和26相比难度如何?
我连备胎都不是却还在...:就暑期实习而言,大厂官宣hc 比 26 多,但是我观察看应该低于 26 的,估计秋招也不简单
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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