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

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

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

select
    uid,
    count(distinct moth) as act_month_total,
    count(
        distinct case
            when year = 2021 then days
        end
    ) as act_days_2021,
    count(
        distinct case
            when year = 2021
            and type = "exam" then days
        end
    ) as act_days_2021,
    count(
        distinct case
            when year = 2021
            and type = "practice" then days
        end
    ) as act_days_2021_exam
from
    (
        select
            uid,
            submit_time,
            date_format (submit_time, "%Y-%m") as moth,
            date_format (submit_time, "%Y-%m-%d") as days,
            date_format (submit_time, "%Y") as year,
            "exam" as type
        from
            exam_record
        union all
        select
            uid,
            submit_time,
            date_format (submit_time, "%Y-%m") as moth,
            date_format (submit_time, "%Y-%m-%d") as days,
            date_format (submit_time, "%Y") as year,
            "practice" as type
        from
            practice_record
    ) t1
    right join user_info using (uid)
where
    level = 7
    or level = 6
group by
    uid
order by
    act_month_total desc,
    act_days_2021 desc

全部评论

相关推荐

喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
05-23 19:02
吉林大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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