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

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

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

with data_for_use as (
    select uid, active_time from (
        select uid, start_time as active_time from exam_record
        union all
        select uid, submit_time as active_time from practice_record) a 
    where uid in (select uid from user_info where level = 6 or level = 7)
), active_month as (
    select uid, count(distinct substr(active_time, 1, 7)) as act_month_total
    from data_for_use group by uid
), active_days_2021 as (
    select uid, count(distinct substr(active_time, 1, 10)) as act_days_2021
    from data_for_use where year(active_time) = 2021 group by uid
), exam_days_2021 as (
    select uid, count(distinct substr(start_time, 1, 10)) as act_days_2021_exam
    from exam_record where year(start_time) = 2021 group by uid
), practice_days_2021 as (
    select uid, count(distinct substr(submit_time, 1, 10)) as act_days_2021_question
    from practice_record where year(submit_time) = 2021 group by uid
)
select uid, ifnull(act_month_total, 0), ifnull(act_days_2021, 0), 
    ifnull(act_days_2021_exam, 0), ifnull(act_days_2021_question, 0)
from user_info
left join active_month using (uid)
left join active_days_2021 using (uid)
left join exam_days_2021 using (uid)
left join practice_days_2021 using (uid)
where level = 6 or level = 7
order by act_month_total desc, act_days_2021 desc

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-19 14:56
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
10-29 21:14
疯犬丨哈士奇:喜欢你的人会主动表白,对你有想法的人会很主动,所以要你的公司不会吊着你所以懂了吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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