本题考查点包括多表合并、分组聚合等,思路较为简单,结合代码解析如下:
select level, count(distinct t1.uid) level_cnt // ④ 查询人数使用去重操作 from exam_record t1 left join user_info t2 on t1.uid = t2.uid left join examination_info t3 on t1.exam_id = t3.exam_id // ① 利用多表连接获得查询的数据源 where tag = "SQL" and score > 80 // ② 筛选条件 group by level // ③ 根据用户等级进行分组 order by level_cnt desc, // ⑤ 先按人数降序排列,再按等级降序排列 level desc

京公网安备 11010502036488号