1.查询课程编号为“01”的课程比“02”的课程成绩高的所有学生的学号(重点)

已知有如下4张表:
学生表:student(学号,学生姓名,出生年月,性别)
成绩表:score(学号,课程号,成绩)
课程表:course(课程号,课程名称,教师号)
教师表:teacher(教师号,教师姓名)

-- 1.查询课程编号为“01”的课程比“02”的课程成绩高的所有学生的学号(重点)
SELECT a.s_id'id',a.s_score'01', b.s_score'02' ,c.s_name FROM

(SELECT s_id,c_id,s_score FROM score  WHERE c_id='01'
)as a
INNER  JOIN
(SELECT s_id,c_id,s_score FROM score  WHERE c_id='02'
)as b ON a.s_id=b.s_id
INNER JOIN student as c ON c.s_id=a.s_id
WHERE a.s_score>b.s_score

1.查询课程编号为“01”的课程比“02”的课程成绩高的所有学生的学号(重点)_第1张图片

SELECT a.s_id,a.s_score'01',b.s_score'02' FROM
(SELECT s_score,s_id,c_id FROM score
WHERE c_id='01') as a
INNER JOIN 
(SELECT s_score,s_id,c_id FROM score
WHERE c_id='02') as b
ON a.s_id=b.s_id
WHERE a.s_score>b.s_score

你可能感兴趣的:(面试题)