with cte_get_active as (
    select uid
    from(
        select uid,start_time as recent_act
        from exam_record
        union all
        select uid,submit_time as recent_act
        from practice_record
    ) t1
    group by uid
    having date_format(max(recent_act),'%Y%m') = 202109
)

select uid,nick_name,achievement
from user_info
join cte_get_active using(uid)
where nick_name like '牛客%号' and achievement between 1200 and 2500
group by uid