select uid,exam_id,round(AVG(score)) as avg_score from user_info join exam_record using(uid) join examination_info using(exam_id) where submit_time is not null and tag rlike '^(?i)c' and nick_name rlike '^牛客[0-9]+号$' OR nick_name rlike '^[0-9]+$' # 这边注意因为AND优先级高,需要把and的条件写在前面 GROUP BY uid,exam_id order by uid asc,avg_score asc