SC成绩表:sid(学号)、cid(课程号)、score(成绩)
course课程表:cid(课程号)、cname(课程名)、tid(教师编号)
怎么查询课程名'001'比课程名'002'成绩高的所有学生的学号
select
sid
from(select sid from SC where cid=(select cid from course where cname='001'))t1
left join (select sid,score from SC where cid=(select cid from course where cname='002')) t2 on t1.sid=t2.sid
where t1.score>ISNULL(t2.score,0)
PS:结果集包含仅001有成绩而002没有成绩的学生学号,如果需要001和002均有成绩的信息,修改为inner join然后where t1.score>t2.score即可