求教sql难题
有三张表,一张是学生姓名表T1,一张是成绩表T2,另外一张是科目表T3
T1 字段有 StudentID Name
T2 StudentID CourseID Score
T3 CourseID CourseName
现在要求用sql写出每门科目都大于平均分的考生的成绩,也就是按T2表输出
------解决方案--------------------select T2.*
from T2,(select CourseID,avg(Score) as avgScore from T2 group by CourseID) as b
where T2.CourseID=b.CourseID and T2.Score> b.avgScore
或
select a.*
from T2 as a
where a.Score> (select avg(Score) from T2 where a.CourseID=CourseID)