UPDATE tblscore SET tblscore.Score= ( -- 这里开始算叶平的平均值 SELECT AVG(tt.aa) FROM ( SELECT tblscore.Score aa FROM tblscore WHERE tblscore.CourseId= ( SELECT tblcourse.CourseId FROM tblcourse WHERE tblcourse.CourseId=( SELECT tblteacher.TeaId FROM tblteacher WHERE tblteacher.TeaName='叶平' ) ))tt -- 算出叶平教得课程的平均值 ) WHERE tblscore.CourseId= (SELECT tblcourse.CourseId FROM tblcourse WHERE tblcourse.CourseId=( SELECT tblteacher.TeaId FROM tblteacher WHERE tblteacher.TeaName='叶平' ))-- 叶平上课的id
答案的写法:
Select * Into Sc From tblScore go Update Sc Set Score=(Select Avg(Score) From tblScore s1 Where s1.CourseId=sc.CourseId) Where CourseId IN (Select CourseId From tblCourse cs INNER JOIN tblTeacher tc ON cs.TeaID=tc.TeaID WHERE TeaName ='叶平')