题解 | #分别满足两个活动的人#

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

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

易错点在于有一位用户2021年各项数据均为0,则需要用left join才能保存下来这位用户:

select uid,count(distinct date_format(submit_time,'%Y%m')) act_month_total,
count(distinct case when year(submit_time) = 2021 then date_format(submit_time,'%Y%m%d') end) act_days_2021,
count(distinct case when year(submit_time) = 2021 and flag = 1 then date_format(submit_time,'%Y%m%d') end) act_days_2021_exam,
count(distinct case when year(submit_time) = 2021 and flag = 0 then date_format(submit_time,'%Y%m%d') end) act_days_2021_question
from user_info left join
(
    select uid,submit_time,1 as flag from exam_record
    union all
    select uid,submit_time,0 as flag from practice_record
) A using(uid)
where level = 6 or level = 7
group by uid
order by 2 desc,3 desc
全部评论

相关推荐

点赞 评论 收藏
分享
08-06 16:46
门头沟学院 Java
这是正常招聘吗?🙄测评颠得要死 真填不下去
鲁大牛:真是个纸张公司。我综测瞎写的还是进笔试了,笔试大部分都空着还是进面试了。一面一口气问了我15道八股文我都答对了,算法也A出来了。结果一面挂了
投递多益网络等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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