您的位置:首页 > 其它

db2中You can't specify target table for update in FROM clause错误

2018-01-02 14:32 453 查看
意思是不能再同一个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='刘老师')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: