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

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

大家好,又见面了,我是你们的朋友全栈君。


意思是不能再同一个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='刘老师')

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/106217.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号