**第一步:**从成绩表中查询“01”
同学所学的所有课程,注意去重
SELECT DISTINCT CId FROM SC WHERE sid = 01;
第二步: 使用in
查询成绩表,查出有与“01”
同学至少一门课程是相同的学生SId
,并排除“01”
学生自身
SELECT DISTINCT SId FROM SC
WHERE CId IN(SELECT DISTINCT CId FROM SC WHERE sid = 01)
AND SId <> 01;
第三步: 查询学生表,获取学生信息
SELECT * FROM student
WHERE SId IN (SELECT DISTINCT SId FROM SC WHERE CId IN (SELECT DISTINCT CId FROM SC WHERE sid = 01)
AND SId <> 01)