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

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

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

提供Mysql下一种相当粗暴的解法……看了一下好像还没有人发过

select user_info.uid, ifnull(count(distinct month),0) a1,
       ifnull(count(distinct day),0) a2,
       ifnull(count(distinct examday),0),
       ifnull(count(distinct questionday),0)
from (
    select uid, date_format(a.start_time,'%Y%m') month,
           if(year(start_time)=2021,date_format(a.start_time,'%Y%m%d'),null) day,
           if(exam_id like '9%' and year(start_time)=2021,date_format(a.start_time,'%Y%m%d'),null) examday,
           if(exam_id like '8%' and year(start_time)=2021,date_format(a.start_time,'%Y%m%d'),null) questionday
    from (select uid,exam_id,start_time from exam_record union
          select uid,question_id,submit_time from practice_record) a) b
right join user_info on user_info.uid = b.uid
where level between 6 and 7
group by uid
order by a1 desc, a2 desc
全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务