题解 | #每个6/7级用户活跃情况#
每个6/7级用户活跃情况
https://www.nowcoder.com/practice/a32c7c8590324c96950417c57fa6ecd1
清晰明了,15行搞定,不用那么复杂
select uid, count(distinct date_format(t, '%Y%m')) act_month_total, count(distinct if(YEAR(t)=2021,date(t),null)) act_days_2021, count(distinct if(YEAR(t)=2021 and tag = 2,date(t),null)) act_days_2021_exam, count(distinct if(YEAR(t)=2021 and tag = 1,date(t),null)) act_days_2021_queston from (select uid,submit_time t,1 tag from practice_record union select uid,submit_time t,2 tag from exam_record) t1 right join user_info using(uid) where level >5 group by uid order by act_month_total desc ,act_days_2021 desc