with t1 as (select uid,max(start_time) as last_time from exam_record group by uid union all select uid, max(submit_time) as last_time from practice_record group by uid), t2 as (select uid, date_format(max(last_time),'%Y%m') as last_time from t1 group by uid) select uid, nick_name,achievement from ...