You can't specify target table 'sc' for update in FROM clause

背景:把“sc”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;

上面的sql是我写的,执行就报这个错,这个原因说的是 不能从自己表里查数据再更新自己

解决方法:嵌套一层中间表

update sc set sc.score =
(select t1.score from (select avg(sc1.score) score from sc sc1 where sc1.c_id=(select course.c_id from teacher,course where course.t_id=teacher.t_id and tname='叶平')) t1)
where sc.c_id = (select course.c_id from teacher,course where course.t_id=teacher.t_id and tname='叶平');

这种问题仅存在于mysql中,在Oracle中是不存在的,因此在此打个mark 以防下次又忘记了

mysql uodate 报错 You can't specify target table '**' for update in FROM clause的更多相关文章

  1. mysql中You can't specify target table for update in FROM clause

    使用mysql在删除表中重复记录 delete from user where username in (select user name form(select username from user ...

  2. mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法

    update语句中包含的子查询的表和update的表为同一张表时,报错:1093-You can’t specify target table for update in FROM clause my ...

  3. mysql出现You can’t specify target table for update in FROM clause

    在mysql执行下面语句时报错: You can’t specify target table for update in FROM clause UPDATE edu_grade_hgm_1 ' W ...

  4. 解决mysql You can't specify target table for update in FROM clause错误

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  5. mysql中You can’t specify target table for update in FROM clause错误解决方法

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  6. mysql 一个较特殊的问题:You can't specify target table for update in FROM clause

    mysql 一个较特殊的问题:You can't specify target table for update in FROM clause 即:不能先select出同一表中的某些值,再update ...

  7. MySQL之You can't specify target table for update in FROM clause解决办法

    这篇文章主要介绍了mysql中You can't specify target table for update in FROM clause错误解决方法,需要的朋友可以参考下 MySQL中You c ...

  8. MySQL 出现You can't specify target table for update in FROM clause错误解决方法

    MySQL出现You can’t specify target table for update in FROM clause 这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值 ...

  9. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

随机推荐

  1. Spring框架中的org.springframework.context.annotation.Import注解类

    @Import注解的作用和在使用spring的xml配置时用到的<import/>类似.但应注意是@Import在使用时必须要保证能被IOC容器扫描到,所以通常它会和@Configurat ...

  2. IntelliJ IDEA 报错:找不到包或者找不到符号

    原因 在网上各种找 https://blog.csdn.net/qq_17213067/article/details/78895302 https://blog.csdn.net/u01398566 ...

  3. Django—模板

    索引 一.模板语言 1.1 变量 1.2 标签 1.3 过滤器 1.4 自定义过滤器 1.5 注释 二.模板继承 三.HTML转义 四.CSRF 五.验证码 六.反向解析 模板 作为Web框架,Dja ...

  4. MySQL----下载安装

    MySQL 的官网下载地址:http://www.mysql.com/downloads/ 注意 1. MySQL Community Server 社区版本,开源免费,但不提供官方技术支持.2. M ...

  5. java获取application.properties和application.yml配置文件信息

    public static void main(String[] args) { String result=getProjectConfig("max-file-size"); ...

  6. Java常见的10个异常

    1.NullPointerException: 空指针异常,当操作一个 null 对象的方法或属性时会抛出这个异常.是一个很头疼的异常,因为它是运行时异常,不需要手动捕获,但运行时碰到这个异常会中断程 ...

  7. 总zabbix配置-搭建-邮件报警-微信报警-监控mysql

    Centos7安装Zabbix4.0步骤 官方搭建zabbix4.0的环境要求: 1. 环境搭建LAMP 前提Centos系统安装完成:  确认一下: 1 2 cat /etc/redhat-rele ...

  8. MYSQL根据节点向上和向下查询所有节点

    WITH cte AS ( SELECT * ,UnitID AS level FROM UnitTable WHERE UnitID=2 UNION ALL SELECT g.*,level+1 F ...

  9. __builtin_expect — 分支预测优化

    1.引言 在很多源码如Linux内核.Glib等,我们都能看到likely()和unlikely()这两个宏,通常这两个宏定义是下面这样的形式. #define likely(x) __builtin ...

  10. 玩转GET 和 POST

    HTTP 基本概念 HTTP Request Methods GET.POST 专业名称是 HTTP Request Methods.但 HTTP Request Methods 不只是 GET 和 ...