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

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

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

select
    ui.uid,
    count(distinct date_format (start_time, '%Y_%m')) as act_month_total,
    count(
        distinct if (
            year (start_time) = 2021,
            date_format (start_time, '%Y%m%d'),
            null
        )
    ) as act_days_2021,
    count(
        distinct if (
            year (start_time) = 2021
            and tag = 'exam',
            date_format (start_time, '%Y%m%d'),
            null
        )
    ) as act_days_2021_exam,
    count(
        distinct if (
            year (start_time) = 2021
            and tag = 'test',
            date_format (start_time, '%Y_%m_%d'),
            null
        )
    ) as act_days_2021_question
from
    (
        select
            uid,
            exam_id as exam_id,
            start_time as start_time,
            'exam' as tag
        from
            exam_record
        union all
        select
            uid,
            question_id as exam_id,
            submit_time as start_time, 'test' as tag
        from
            practice_record
    ) as total
right join user_info as ui
on ui.uid = total.uid
where ui.level >= 6
group by
    ui.uid
order by act_month_total desc, act_days_2021 desc

全部评论

相关推荐

最近和朋友聊天,她说了句让我震惊的话:"我发现我连周末点外卖都开始'最优解'了,一定要赶在高峰期前下单,不然就觉得自己亏了。"这不就是典型的"班味入侵"吗?工作思维已经渗透到生活的方方面面。
小型域名服务器:啊?我一直都这样啊?我还以为是我爱贪小便宜呢?每次去实验室都得接一杯免费的开水回去,出门都得规划一下最短路径,在宿舍就吃南边的食堂,在实验室就吃北边的食堂,快递只有顺路的时候才取。
点赞 评论 收藏
分享
joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务