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

每个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
全部评论

相关推荐

预计下个星期就能开奖吧,哪位老哥来给个准信
华孝子爱信等:对接人上周说的是这周
点赞 评论 收藏
分享
jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
11-11 14:21
西京学院 C++
Java抽象练习生:教育背景放最前面,不要耍小聪明
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务