查询一门成绩高于另一门课程的学生信息
分析思路:
一、将子查询结果作为表,筛选数据
1、将这两门课程按学号分组展示
2、将上面的查询结果作为表,再筛选合适的数据
select * from
(
SELECT
sno,
max(case when cno='3-105' then DEGREE else 0 end) dg105,
max(case when cno='3-245' then DEGREE else 0 end) dg245
FROM score
where CNO in ('3-105','3-245')
group by sno
) a
where a.dg105>0 and a.dg245>0 and a.dg105>a.dg245
二、将成绩表做关联查询
SELECT * FROM score a, score b
WHERE a.SNO=b.SNO
AND a.CNO='3-105'
AND b.CNO='3-245'
AND a.DEGREE>b.DEGREE
越努力,越幸运!
转载请注明出处,商用需征得作者同意,谢谢!