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='刘老师')
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='刘老师')
相关文章推荐
- db2 字段大小写的区别
- db2创建索引原则
- DB2 事务日志已满 增加事务日志文件;操作不记录日志
- DB2 递归例子
- db2 +/- options
- 【DB2问题解决】SQL1042C SQL1032N SQLSTATE=57019
- db2常用命令大全
- DB2_9表分区
- Linux下db2配置远程连接
- DB2 LIKE escape-expression
- DB2的CATALOG相关操作命令示例
- Oracle、DB2、SQLSERVER、Mysql、Access分页SQL语句梳理
- 图解DB2 Express-C 9.5在Windows下的安装
- DB2 v9.7中不建议使用的工具
- db2 oracle 创建 序列
- DB2 分区表增加分区
- db2 快速清空表数据
- DB2时间日期类型简介
- DB2错误信息(按sqlcode排序)
- Installing DB2 for Linux under FreeBSD using Linux compat