最近面试了几个人,给他们出了一道SQL语句面试题,但是反应效果不太理想。题目如下:
表scores有四个字段,学生stu、班级class、学院institute、分数score。
要求返回:班级考试人数大于10、班级最低分在50分以上、计算机学院、班级平均分从高到低前10名。
可以用任意数据库写SQL
返回字段为班级,平均分。
--不准嵌套语句。
select top 10 class,平均分=avg(score) from tb
where institute='计算机学院'
group by class having count(1)>=10 and min(score)>=50
order by avg(score) desc