意思是不能再同一个sql语句中对同一个表先查询在更新,解决办法是在查询部分的语句中加上别名;错误的如下:
update Sc set score =(
select avg(sc2.score) aa from sc sc2 ,course where sc2.c=course.c
)
where c in
(select c from test.course cs inner join test.teacher th on cs.T=th.T and th.Tname='刘老师')正确的如下:对第二行的查询结果加上别名a就行了update Sc set score =(
select a.aa from (
select avg(sc2.score) aa from sc sc2 ,course where sc2.c=course.c
) a)
where c in
(select c from test.course cs inner join test.teacher th on cs.T=th.T and th.Tname='刘老师')
本文介绍了如何在SQL中正确地使用子查询进行更新操作,避免在同一语句中对同一表进行查询和更新时出现的问题,并给出了具体的示例。
4016

被折叠的 条评论
为什么被折叠?



