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

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

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

select c1.uid,act_month_total,ifnull(act_days_2021,0) act_days_2021,ifnull(act_days_2021_exam,0),ifnull(act_days_2021_question,0) from
    (select d.uid uid,count(distinct month) act_month_total from
    (select a.uid uid,date_format(start_time,'%Y%m') month from
    (select * from user_info where level in (6,7)) a
    left join exam_record b
    using(uid)
    group by uid,date_format(start_time,'%Y%m')
    union
    select a.uid uid,date_format(submit_time,'%Y%m') month from
    (select * from user_info where level in (6,7)) a
    left join practice_record b
    using(uid)
    group by uid,date_format(submit_time,'%Y%m')) d
    group by uid) c1
left join
(select d.uid uid,count(distinct day) act_days_2021 from
    (select a.uid uid,date_format(start_time,'%Y%m%d') day from
    (select * from user_info where level in (6,7)) a
    left join exam_record b
    using(uid)
    where year(start_time) = 2021
    group by uid,date_format(start_time,'%Y%m%d')
    union
    select a.uid uid,date_format(submit_time,'%Y%m%d') day from
    (select * from user_info where level in (6,7)) a
    left join practice_record b
    using(uid)
    where year(submit_time) = 2021
    group by uid,date_format(submit_time,'%Y%m%d')) d
    group by uid) c2
using(uid)
left join
    (select t1.uid uid,count(distinct day1) act_days_2021_exam,count(distinct day2) act_days_2021_question from
    (select a.uid uid,date_format(start_time,'%Y%m%d') day1 from
    (select * from user_info where level in (6,7)) a
    left join exam_record b
    using(uid)
    where year(start_time) = 2021
    group by uid,date_format(start_time,'%Y%m%d')) t1
    left join
    (select a.uid uid,date_format(submit_time,'%Y%m%d') day2 from
    (select * from user_info where level in (6,7)) a
    left join practice_record b
    using(uid)
    where year(submit_time) = 2021
    group by uid,date_format(submit_time,'%Y%m%d')) t2
    using(uid)
    group by uid) c3
using(uid)
order by act_month_total desc,act_days_2021 desc
用了连接、合并
全部评论

相关推荐

10-15 20:01
已编辑
上海大学 Java
钉钉什么垃圾公司,约面鸽人
Syca_:途虎养车给我定了我这边早上六点的笔试,睡了四个小时起来难受的要命,告诉我面试时间是两天后的凌晨四点
点赞 评论 收藏
分享
10-09 16:12
门头沟学院 Java
帅宇殿下:佬,简历写的什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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