--学生表tblStudent(编号StuId、姓名Stuname、年龄Stuage、性别Stusex)
--课程表tblCourse(课程编号CourseId、课程名称CourseName、教师编号TeaId)
--成绩表tblScore(学生编号StuId、课程编号CourseId、成绩Score)
--教师表tblTeacher(教师编号TeaId、姓名TeaName)
--13、把“SC ”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; (从子查询中获取父查询中的表名,这样也行????)
--查询教师编号
select * from tblTeacher te where te.teaname='叶平'
--查询‘叶平’教的课程
select * from tblCourse co where co.teaid='002'
--查询‘叶平’教的课程的成绩表
select * from tblScore sc where sc.courseid in (001,016)
--查询平均值
select sc.courseid,count(*),avg(sc.score) from tblScore sc where sc.courseid in (
select co.courseid from tblCourse co where co.teaid in(
select te.teaid from tblTeacher te where te.teaname='叶平'
)
) group by sc.courseid
--修改平均值
update tblScore sc set sc.score=(
--这里从子查询中获取父查询中的表名 使平均值的课程等于父类条件的课程
select avg(score) from tblscore where courseid=sc.courseid
)
where sc.courseid in (
select co.courseid from tblCourse co where co.teaid in(
select te.teaid from tblTeacher te where te.teaname='叶平'
)
);
--再次查询‘叶平’教的课程的成绩表看看是否修改成功
select * from tblScore sc where sc.courseid in (001,016)