sql 经典练习 ()
--1. 查询01 课程比02 课程 成绩高的学生以及课程分数. --查询课程1,和分数, select * from SC sc where sc.CId='01' ---查询课程2 和分数 , select * from SC sc2 where sc2.CId='02' select * from Student RIGHT JOIN ( select t1.SId,t1.class1,t2.class2 from (select sc.SId,sc.score as class1 from SC sc where sc.CId='01' )as t1, (select sc2.SId,sc2.score as class2 from SC sc2 where sc2.CId='02') as t2 where t1.SId=t2.SId and t1.class1>t2.class2 ) r on Student.SId = r.SId; ---2.平均分 高于60分的同学的情况 select s.Sname,s.SId ,k.平均分 from Student s inner join (select sc.SId,AVG(sc.score) as 平均分 from SC sc group by sc.SId )k on s.SId=k.SId --3. 成绩表中