with cte_get_uid as ( select uid, level from user_info join exam_record using(uid) join examination_info using(exam_id) where tag='SQL' and score>80 ) # with 子查询获取符合条件的用户 select level, count(uid) as level_cnt # 对等级分组后计算每组uid数量 from cte_get_uid group by level order by level_cnt desc # 降序排序