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

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

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

with tiaojian as (
select
uid
from user_info
where
level in (6,7)
),
tiaojian1 as (
select
uid,exam_id,"exam_id" as pt,date(submit_time) as pday,date_format(submit_time,"%Y-%m") as month
from exam_record
union all
select
uid,question_id, "question_id" as pt,date(submit_time) as pday,date_format(submit_time,"%Y-%m") as month
from practice_record
)

select
t.uid,
count(distinct t1.month) as month,
count(distinct case when year(t1.pday)=2021 then t1.pday end) as pday,
count(distinct case when year(t1.pday)=2021 and t1.pt="exam_id" then t1.pday end),
count(distinct case when year(t1.pday)=2021 and t1.pt="question_id" then t1.pday end)
from tiaojian  t left join tiaojian1 t1 on t.uid=t1.uid
group by t.uid
order by month desc,pday desc

全部评论

相关推荐

2024-12-29 15:37
已编辑
西华大学 图像识别
程序员牛肉:去不了,大厂算法卡学历吧
点赞 评论 收藏
分享
2024-11-22 23:00
华南理工大学 Java
求美团让我成为团孝子:帅不帅的不知道 不过我真是拨号机小姐的狗啊
投递TP-LINK等公司8个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务