今天在写Mysql代码作业时,写到这个题,感觉值得分享!!!!!!!
查询"01"课程比"02"课程成绩高的学生的信息及课程分数
分析如下:
首先先查询"01"课程比"02"课程成绩高的两个课程分数,以及该学生学号
select s1.s_id,s1.s_score 01score,s2.s_score 02score
from Score s1,Score s2
where s1.s_id=s2.s_id and
s1.c_id='01' and
s2.c_id='02' and
s1.s_score >s2.s_score;
然后将查到的该学生的学号与学生表中的学号联系起来,就得到了本题的答案
select s.*,s1.s_score 01score,s2.s_score 02score
from Score s1,Score s2,Student s
where s.s_id=s1.s_id and
s1.s_id=s2.s_id and
s1.c_id='01' and
s2.c_id='02' and
s1.s_score >s2.s_score;
我认为这样做比较清晰,查询"01"课程比"02"课程成绩低的学生的信息及课程分数转换比较符号即可。