select a.SId from(select*from Score where CId ='01')as a
innerjoin(select*from Score where CId ='02')as b
on a.SId = b.SId
where a.score>b.score
方法二:CTE
with score01 as(select*from Score where CId ='01'), score02 as(select*from Score where CId ='02')select score01.SId,score01.CId from score01 innerjoin score02
on score01.SId = score02.SId
where score01.score> score02.score
2. 查询没学过“张三”老师课的学生和学号
with zs as(select*from Score sc
leftjoin Teacher t
on sc.c_id = t.t_id
where t_name ='张三')select s.s_id,s.s_name from Student s
leftjoin zs
on s.s_id = zs.s_id
where zs.t_name isnull