LeetCode 【困难】数据库-第1412 :查找成绩处于中游的学生

题目

数据

结果

解答

1.

select distinct(Exam.student_id) as STUDENT_ID,
	    Student.student_name as STUDENT_NAME 
from Exam 
join Student on Student.student_id = Exam.student_id

2.结果、撇去最高、最低分。

select distinct(Exam.student_id) as STUDENT_ID,
	    Student.student_name as STUDENT_NAME 
from Exam 
join Student on Student.student_id = Exam.student_id

where Exam.student_id not in
	(select distinct(student_id) from Exam 
			where (exam_id,score) in(select exam_id,max(score) as score from exam group by exam_id)  # 实验最高分
			or
			      (exam_id,score) in(select exam_id,min(score) as score from exam group by exam_id)  # 实验最低分
	) 
order by Exam.student_id asc;

posted @ 2021-07-08 19:04  hangover  阅读(68)  评论(0编辑  收藏  举报