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

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

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

select
    uid,
    count(distinct exam_mon) as act_month_total,
    count(
        distinct case
            when year (act_time) = 2021 then exam_day
            else null
        end
    ) as act_days_2021,
    count(
        distinct case
            when year (act_time) = 2021
            and tag = 'exam' then exam_day
            else null
        end
    ) as act_days_2021_exam,
    count(
        distinct case
            when year (act_time) = 2021
            and tag = 'pra' then exam_day
            else null
        end
    ) as act_days_2021_question
from
    user_info ui
    left join (
        select
            uid,
            start_time as act_time,
            date_format (start_time, "%Y%m%d") as exam_day,
            date_format (start_time, "%Y%m") as exam_mon,
            "exam" as tag
        from
            exam_record
        union all
        (
            select
                uid,
                submit_time as act_time,
                date_format (submit_time, "%Y%m%d") as exam_day,
                date_format (submit_time, "%Y%m") as exam_mon,
                "pra" as tag
            from
                practice_record
        )
    ) as exam using (uid)
where
    ui.level >= 6
group by
    uid
order by
    act_month_total desc,
    act_days_2021 desc

看评论区写的,先查出 试卷和联系作答的月份和时间。因为总活跃天数和月份可以用到这些数据,之前想着先查出来在合并,但是那样就复杂了,这个思路很好

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-23 18:33
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
感觉今年拿到大厂实习offer的人很多,光是身边同学室友都是好几个offer。由此可见,秋招得有多卷
小浪_Coding:必须卷的起飞, 应该比25更卷一点, 25已经是哀声一片了, 26会更难一点, 现在还有`很多25未找到的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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